Apps Home
|
Create an App
BattleForGlory
Author:
samupo
Description
Source Code
Launch App
Current Users
Created by:
Samupo
/********************************************************************************* Author: Samupo Title: BattleForGlory Description: Viewers must help the broadcaster's hero fight against a bad guy to reach a goal. Change Log: v1.0 - 2014-09-08: Initial release. **********************************************************************************/ cb.settings_choices = [ {name: 'goal', type: 'str', defaultValue:"Flash something", minLength: 1, maxLength: 255, label: "Goal"}, {name: 'show_goal', type: 'choice', choice1:"Show goal", choice2:"Don't show goal", label: "Show goal before reaching it?"}, {name: 'hero_name', type: 'str', defaultValue:"", minLength: 3, maxLength: 32, label: "Hero's name"}, /*{name: 'hero_best_tipper', type: 'choice', choice1:"Enabled", choice2:"Disabled", label: "Hero is best tipper?"},*/ {name: 'boss_name', type: 'str', defaultValue:"", minLength: 3, maxLength: 32, label: "Bad guy's name"}, {name: 'boss_health', type: 'int', minValue:1, maxValue: 100000, defaultValue: 250, label: "Bad guy's health (tokens to reach goal)"}, {name: 'boss_min_combo', type: 'int', minValue:0, maxValue: 120, defaultValue: 1, label: "[GameSetting] Bad Guy's min combo"}, {name: 'boss_max_combo', type: 'int', minValue:1, maxValue: 120, defaultValue: 3, label: "[GameSetting] Bad Guy's max combo"}, {name: 'boss_damage', type: 'int', minValue:1, maxValue: 100, defaultValue: 10, label: "[GameSetting] Bad Guy's hit damage (1 to 100% of accumulated tokens)"} ]; var boss_name; var boss_max_health; var boss_health; var hero_name; var hero_health = 1; var hero_combo = 0; //Game Settings var goal; var show_goal; var boss_min_combo; var boss_max_combo; var boss_damage; /*var hero_best_tipper;*/ const TICKTIME = 30000; const YELLOW_COMBO = 1.1; function loadSettings() { goal = cb.settings.goal; if (cb.settings.show_goal == "Show goal") { show_goal = true; } else { show_goal = false; } hero_name = cb.settings.hero_name; /*if (cb.settings.hero_best_tipper == "Enabled") { hero_best_tipper = true; } else { hero_best_tipper = false; }*/ boss_name = cb.settings.boss_name; boss_max_health = cb.settings.boss_health; boss_health = cb.settings.boss_health; boss_damage = cb.settings.boss_damage; boss_min_combo = cb.settings.boss_min_combo; boss_max_combo = cb.settings.boss_max_combo; } function getBossHealthPercentage() { return Math.floor(100 * boss_health / boss_max_health); } function getSubject() { var subject = '#BattleForGlory Help ' + hero_name + ' fight against ' + boss_name + ' <' + getBossHealthPercentage() +'% health remaining >'; if (show_goal) { subject += ' [Goal: ' + goal + ']'; } return subject; } function getRandom(min, max) { var num = Math.random(); num = num*(max-min); num += min; return Math.floor(num); } function tick() { var boss_combo = getRandom(boss_min_combo, boss_max_combo); if (boss_combo > hero_combo) { cb.sendNotice(boss_name + ' attacks ' + hero_name + '!'); var health_lost = Math.floor(boss_damage * hero_health / 100); cb.sendNotice(hero_name + ' loses ' + health_lost + ' health!'); hero_health -= health_lost; cb.sendNotice('You need to tip to make ' + hero_name + ' victorious!'); } else if (boss_combo == hero_combo) { if (getRandom(0, 10) > 5) { cb.sendNotice(hero_name + ' attacks ' + boss_name + '!'); cb.sendNotice('Unfortunately ' + boss_name + ' evades the attack...'); } else { cb.sendNotice(boss_name + ' attacks ' + hero_name + '!'); cb.sendNotice(hero_name + ' manages to evade the attack!'); } } else { cb.sendNotice(hero_name + ' attacks ' + boss_name + '!'); var health_lost = Math.floor(hero_health / 2); hero_health -= health_lost; cb.sendNotice(hero_name + ' gets tired...'); if (hero_combo > 10) { cb.sendNotice('YELLOW WALL COMBO!!!'); health_lost = Math.floor(health_lost * YELLOW_COMBO); } cb.sendNotice(boss_name + ' loses ' + health_lost + ' health!'); boss_health -= health_lost; } hero_combo = 0; cb.drawPanel(); cb.changeRoomSubject(getSubject()); if (boss_health > 0) cb.setTimeout(tick, TICKTIME); else { cb.sendNotice(boss_name + ' HAS BEEN DEFEATED!!!'); cb.sendNotice(cb.room_slug + ' HAS BEEN SAVED AND THANKS YOU [' + goal + ']'); cb.changeRoomSubject('#BattleForGlory Battle is over [Goal: ' + goal + ']'); } } cb.onTip(function (tip) { hero_health += parseInt(tip['amount']) hero_combo += 1; cb.sendNotice(hero_name + '\'s health: ' + hero_health); cb.drawPanel(); cb.changeRoomSubject(getSubject()); }); cb.onDrawPanel(function(user) { var str0 = boss_name + '\'s health: ' + getBossHealthPercentage() + '%'; var str1 = hero_name + '\'s health: ' + hero_health; var str2 = 'Tip combo: ' + hero_combo; return { 'template': '3_rows_11_21_31', 'row1_value': str0 , 'row2_value': str1, 'row3_value': str2 }; }); function start() { loadSettings(); cb.changeRoomSubject(getSubject()); cb.drawPanel(); cb.sendNotice(boss_name + ' kidnapped ' + cb.room_slug + '!!!'); cb.sendNotice('You must help ' + hero_name + ' save ' + cb.room_slug + '.'); cb.sendNotice('Tips improve ' + hero_name + '\'s health and help the fight.'); cb.setTimeout(tick, TICKTIME*5); } cb.onMessage(function (msg) { var message = msg['m']; var user = msg['user']; var param = ""; if (cb.room_slug === user && message == '/start') { start(); } });
© Copyright Chaturbate 2011- 2026. All Rights Reserved.