Apps Home
|
Create an App
Clothing Battle 2
Author:
atrixtest
Description
Source Code
Launch App
Current Users
Created by:
Atrixtest
// Clothing Battle 2 // // coded by Sleepwalker7, 2014 // // This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. // contact me if you have any questions or comments. 7sleepwalker@gmail.com /* ABOUT THIS APP ============== Define three items of clothing, leave entry 2 or 3 blank if you don't wish to use it. Each item of clothing has an amount of "Hit Points" and when they are used up the item must be removed. Each item will take damage of a random number up to it's MaximumDamage value. It can block, and take zero damage, and it can fight back and regain up to it's MaximumDamage worth in healthpoints back. Viewers attack an item of clothing by tipping the associated tip value to select it. */ // have the user setup the app cb.settings_choices = []; for (i=1; i<4; i++) { cb.settings_choices.push ( {name: "clothing"+i+"Name", type: "str", minLength: 1, maxLength: 21, label: "Item "+i+" name", defaultValue: "", required: false}, {name: "clothing"+i+"HitPoints", type: "int", minValue: 1, maxValue: 1000, label: "Starting hit points", defaultValue: 100, required: false}, {name: "clothing"+i+"MaxDamage", type: "int", minValue: 1, maxValue: 1000, label: "Max damage each hit", defaultValue: 25, required: false}, {name: "clothing"+i+"TipValue", type: "int", minValue: 1, maxValue: 1000, label: "Tip value for this item", defaultValue: 30, required: false} ); } // vars var clothing = new Array(); for (item = 0; item < 3; item ++) { clothing[item] = [ cb.settings["clothing"+(item+1)+"Name"] ,cb.settings["clothing"+(item+1)+"HitPoints"] ,cb.settings["clothing"+(item+1)+"MaxDamage"] ,cb.settings["clothing"+(item+1)+"TipValue"] ]; } // draw panel cb.onDrawPanel(function(user) { var defeatedText = "*** DEFEATED! ***"; var rowLabels = new Array(); var rowValues = new Array(); for (item = 0; item < 3; item ++) { rowLabels[item] = clothing[item][0].length > 0 ? clothing[item][0] + " (tip " + clothing[item][3] + ")" : " "; rowValues[item] = clothing[item][1]>0 ? "points remaining: " + clothing[item][1] : defeatedText ; rowValues[item] = clothing[item][0].length > 0 ? rowValues[item] : " "; // clear it if there is no item name } var fields = { template: '3_rows_of_labels', row1_label: rowLabels[0], row1_value: rowValues[0], row2_label: rowLabels[1], row2_value: rowValues[1], row3_label: rowLabels[2], row3_value: rowValues[2] }; return fields; }); // game logic cb.onTip(function (data) { // work out which item is being tipped for var tipValue = parseInt(data["amount"]); var tippedItem = -1; if (tipValue == clothing[0][3] && clothing[0][0]) { tippedItem = 0 } if (tipValue == clothing[1][3] && clothing[1][0]) { tippedItem = 1 } if (tipValue == clothing[2][3] && clothing[2][0]) { tippedItem = 2 } if (tippedItem > -1) { // check for already defeated if (clothing[tippedItem][1] < 1) { cb.sendNotice("That item is no longer being worn", "", "", "#ff8900", "bold"); } else { // valid item has been tipped for, get a random damage number var attackStrength = Math.floor((Math.random() * (clothing[tippedItem][2]+2)) -1); var damageTaken = 0; var damageMessage = ""; // if 0, the clothing defends and takes no damage if (attackStrength == 0) { damageMessage = clothing[tippedItem][0] + " defended itself and took no damage at all!"; } // if negative, the clothing defends and gains health if (attackStrength < 0) { var gainedPoints = Math.floor(Math.random() * clothing[tippedItem][2]); damageMessage = clothing[tippedItem][0] + " blocked your attack and feels rather good about it, healing by " + gainedPoints + " points as a result!"; } // positive damage if (attackStrength > 0) { var pluralVerb = "was"; if (clothing[tippedItem][0].slice(-1).toLowerCase() == "s") { pluralVerb = "were"; } damageMessage = clothing[tippedItem][0] + " " + pluralVerb + " attacked and took " + attackStrength + " points of damage."; } cb.sendNotice(damageMessage, "", "", "#740000", "bold"); clothing[tippedItem][1] = clothing[tippedItem][1] - attackStrength; // check for defeated if (clothing[tippedItem][1] < 1) { // defeated var pluralVerb = "has"; if (clothing[tippedItem][0].slice(-1).toLowerCase() == "s") { pluralVerb = "have"; } var itemDefeatedMessage = clothing[tippedItem][0] + " " + pluralVerb + " been defeated!"; cb.sendNotice(itemDefeatedMessage, "", "", "#ff0000", "bold"); } // check for naked! if (clothing[0][1] < 1 && clothing[1][1] < 1 && clothing[2][1] < 1) { cb.sendNotice("Game completed! All clothing gone, congratulations!", "", "", "#ff00ce", "bold"); } cb.drawPanel(); } } }); // display help when requested cb.onMessage(function (data) { if (data["m"] == "!help") { data['X-Spam'] = true; var helpText = ":clothingbattle2\nItems of clothing are shown in the panel below the video. Each item has a number of 'hitpoints' and when they're gone, the item of clothing is defeated and must be removed.\nTip to 'attack' the clothes! Tip the number printed next to the item to choose your target. Have fun!!"; if (data['user'] == cb.room_slug || data['is_mod']) { cb.sendNotice(helpText, "", "", "#417900", "normal"); } else { cb.sendNotice(helpText, data["user"], "", "#417900", "normal"); } } return data; }); // inform user on join cb.onEnter(function(data) { if (data["user"] != cb.room_slug) { cb.sendNotice("Clothing Battle app is running, type !help for details.", data["user"], "", "#67c200", "bold"); cb.drawPanel(); } }); // repeated info message function repeatingMessage() { cb.sendNotice("Clothing Battle app running, type !help for instructions.", "", "", "#3072ff", "bold"); cb.setTimeout(repeatingMessage, 180000) } // update the panel when the app is launched function init() { cb.sendNotice(":clothingbattle2 is now running. Type !help for instructions.", "", "", "#67c200", "bold"); cb.drawPanel(); cb.setTimeout(repeatingMessage, 180000) } init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.