Fix hair, dick around with new game screen.
[18plus-7leafadventure.git] / src / org / sevenchan / dongs / screens / CombatScreen.as
blob3376278f761ef8ac1332785e40b90a87ea9ddd35
1 package org.sevenchan.dongs.screens
3 import org.sevenchan.AdventureController;
4 import flash.accessibility.Accessibility;
5 import org.sevenchan.dongs.bodyparts.Arm;
6 import org.sevenchan.dongs.bodyparts.IBodyPart;
7 import org.sevenchan.dongs.Creature;
8 import org.sevenchan.dongs.creature.Player;
9 import org.sevenchan.dongs.enchantment.Enchantment;
10 import org.sevenchan.dongs.enchantment.events.CombatEndEvent;
11 import org.sevenchan.dongs.enchantment.events.CombatTurnEvent;
12 import org.sevenchan.dongs.enchantment.Paralyze;
13 import org.sevenchan.dongs.Screen;
14 import org.sevenchan.dongs.Ability;
15 import org.sevenchan.dongs.Town;
16 import org.sevenchan.dongs.towns.TownBarn;
17 import org.sevenchan.dongs.weapons.IWeapon;
19 /**
20 * ...
21 * @author Harbinger
23 public class CombatScreen extends Screen
25 public var passAction:int = -1;
27 public static const PASS_SKIP:int = -2;
28 public static const PASS_NONE:int = -1;
29 public static const PASS_ATTACK:int = 0;
30 public static const PASS_RUN:int = 3;
31 public static const PASS_FORFEIT:int = 4;
32 public static const PASS_RAPE:int = 5;
34 private var oldScreen:Screen;
35 private var combatant:Creature;
36 private var text:String = "";
37 private var act:String = "";
38 private var playerInitiated:Boolean;
39 // Combat
40 // Attack Items Abilities Run Forfeit
41 // Attack
42 // Punch Kick Headbutt
43 public function CombatScreen(prevScrn:Screen,c:Creature,playerInitiated:Boolean)
45 oldScreen = prevScrn;
46 combatant = c;
47 this.playerInitiated = playerInitiated;
48 clearButtons();
51 override public function processButtonPress(id:int):Boolean
53 main.refreshStats();
54 clearButtons();
55 if (main.player.getInterested(combatant))
56 lustCost = 1;
57 else
58 lustCost = 0;
60 if (id == -1 && act=="")
62 act = "main";
63 combatant.onCombatInit(main.player);
64 if(playerInitiated) {
65 tryAttack(main.player, combatant);
66 return true;
69 text = "<h2>Fight</h2>";
70 text += combatant.combatDescr(main.player);
71 text += "<p><b>Attacker's HP:</b> " + combatant.HP + "/" + combatant.maxHP + " (" + Math.round((combatant.HP / combatant.maxHP) * 100) + "%)</p>";
72 text += "<p><b>Attacker's Level:</b> "+combatant.level+" (STR"+combatant.strength+" SPD"+combatant.speed+")</p>";
73 if ("main" == act)
74 return mainMenu(id);
75 if ("attack" == act)
76 tryAttack(main.player, combatant);
77 if (combatant.HP<=0)
79 win();
80 return true;
82 if (main.player.HP<=0)
84 lose();
85 return true;
87 if ("items" == act) {
88 AdventureController.screenQueue.write(new InventoryScreen());
89 return true;
91 if ("abilities" == act) {
92 return abilitiesMenu(id);
95 return false;
97 private function mainMenu(id:int):Boolean {
98 clearButtons();
99 if (!Enchantment.isLockedOut(main.player)) {
100 if(Enchantment.canAttack(main.player,combatant))
101 setButton(0, "Attack");
102 setButton(1, "Items");
103 setButton(2, "Abilities");
104 if (Enchantment.canRun(main.player,combatant) && combatant.canRun())
105 setButton(3, "Run");
106 setButton(4, "Forfeit");
107 if (combatant.getRapable())
108 setButton(5, "Rape");
109 } else {
110 setButton(0, Enchantment.getLockoutEffectText(main.player));
113 switch(id) {
114 case 0://attack
115 var bypassNotification:Boolean = passAction == -3;
116 passAction = -1;
117 if (!bypassNotification)
118 main.player.notifyEnchantments(new CombatTurnEvent(this,combatant));
119 //if (Paralyze.isParalyzed(main.player))
121 // InfoScreen.push("<h2>Paralyzed</h2><p>You are paralyzed, so you can't do <em>shit</em>.</p>");
122 if (passAction != -1) {
123 if(passAction==-2) {
124 // Skip entirely.
125 combatant.yourMove(this, main.player);
126 }else {
127 passAction = -3; // Just in case we're forcing attack
128 // Force an action
129 mainMenu(passAction);
131 } else {
132 tryAttack(main.player, combatant);
134 if (combatant.HP<=0)
136 win();
137 return true;
139 if (main.player.HP<=0)
141 lose();
142 return true;
144 if (main.player.lust>=100)
146 lose();
147 return true;
149 return true;
150 break;
151 case 1: //Items
152 AdventureController.screenQueue.write(new InventoryScreen());
153 return true;
154 break;
155 case 2:
156 act = "abilities";
157 return abilitiesMenu( -1);
158 break;
159 case 3:
160 if (main.player.speed - combatant.speed > -1) {
161 text = "<p>You successfully manage to get away!</p>";
162 main.endCombat(oldScreen);
163 } else {
164 text = "<p>You're unable to get away!</p>";
165 main.player.notifyEnchantments(new CombatTurnEvent(this,combatant));
167 updateScreen();
168 return true;
169 break;
170 case 4:
171 lose();
172 return true;
173 break;
174 case 5:
175 main.startRape(this, combatant, true);
176 return true;
177 break;
179 updateScreen();
180 return false;
182 private function abilitiesMenu(id:int):Boolean {
183 clearButtons();
184 setButton(0, "CANCEL");
185 var ab:Array = [];
186 text = "<h2>Abilities</h2>";
188 if(MathUtils.lengthOf(main.player.abilities)>0) {
189 text += "<p>Here are the abilities you currently possess:<ul>";
190 for (var k:String in main.player.abilities) {
191 ab.push(main.player.abilities[k]);
194 for (var i:int = 1; i < 12; i++) {
195 var ability:Ability = (ab[i - 1] as Ability);
196 if(ability!=null) {
197 setButton(i, ability.label);
198 text += "<li><b>" + ability.name + "</b> - " + ability.description + "</li>";
201 text += "</ul></p>";
203 else {
204 text += "<p><i>You don't have any abilities at the moment.</i></p>";
206 if (id == -1) {
207 updateScreen();
208 return false;
210 if (id == 0) {
211 act = "main";
212 return processButtonPress(-1);
213 } else {
214 (ab[id - 1] as Ability).activate(main.player, combatant);
215 main.player.notifyEnchantments(new CombatTurnEvent(this,combatant));
216 if (combatant.HP<=0)
218 win();
219 return true;
221 if (main.player.HP<=0)
223 lose();
224 return true;
226 if (main.player.lust>=100)
228 main.startRape(this,combatant,true);
229 return true;
231 act = "main";
232 return true;
235 override public function getScreenText():String
237 return text;
240 private function limbMissed(limb:IBodyPart, from:Creature, to:Creature):Boolean {
241 var chances:Number = (from.speed - to.speed);
242 trace("Probability of " + limb.getDescr(1,from) + " successfully attacking: " + (chances/100));
243 return (/*to.counter(limb) &&*/ Math.random() * 100 <= chances);
246 private function weaponMissed(weapon:IWeapon, from:Creature, to:Creature,hostLimb:IBodyPart):Boolean {
247 var chances:Number = (from.speed - to.speed);
248 trace("Probability of " + weapon.getDescr(1,from,hostLimb) + " successfully attacking: " + (chances/100));
249 return (/*to.counter(limb) &&*/ Math.random() * 100 <= chances);
252 public function tryAttack(from:Creature, to:Creature):void {
253 // Check if paralyze affects from
254 if (from.arms.length > 0 && (from.legs.length==0 || MathUtils.rand(0,1) == 0)) {
255 var arm:IBodyPart = MathUtils.getRandomVectorEntry(Vector.<*>(from.arms));
256 if (arm.weapon != null) {
257 if(weaponMissed(arm.weapon,from,to,arm))
258 arm.weapon.onFailedAttack(from, to);
259 else
260 arm.weapon.onGoodAttack(from, to);
261 } else {
262 if(limbMissed(arm,from,to))
263 arm.onFailedAttack(from,to);
264 else
265 arm.onGoodAttack(from, to);
267 to.yourMove(this,main.player);
268 return;
270 if (from.legs.length > 0) {
271 var leg:IBodyPart = MathUtils.getRandomVectorEntry(Vector.<*>(from.legs));
272 if(limbMissed(leg,from,to))
273 leg.onFailedAttack(from,to);
274 else
275 leg.onGoodAttack(from,to);
276 to.yourMove(this,main.player);
277 return;
279 var txt:String = "";
280 if(from is Player)
281 text = "<p>You don't have arms or legs, so you can't attack!</p>";
282 else
283 text = "<p>Your attacker doesn't have arms or legs, so it can't attack!</p>";
284 //txt += "<p>Arms: " + from.arms.length +"</p>";
285 //txt += "<p>Legs: " + from.legs.length +"</p>";
286 AdventureController.screenQueue.write(new InfoScreen(txt));
287 to.yourMove(this,main.player);
290 private function notifyEnchOfCombatEnd(host:Creature, other:Creature, winning:Boolean):void {
291 for (var k:String in host.enchantments) {
292 host.enchantments[k].onCombatComplete(winning, other);
296 private function win():void {
297 combatant.notifyEnchantments(new CombatEndEvent(false,main.player));
298 main.player.notifyEnchantments(new CombatEndEvent(true,combatant));
299 main.player.gold += combatant.gold;
300 main.player.XP += 6+((main.player.level - combatant.level)*1);
301 if (!combatant.onLose(main.player)) {
302 WinnerScreen.push(main.player,combatant);
304 main.endCombat(oldScreen);
305 return;
308 private function lose():void {
309 main.player.HP = main.player.maxHP;
310 main.player.gold -= 30;
311 main.player.currentTown = Town.knownTowns["barn"];
312 combatant.notifyEnchantments(new CombatEndEvent(true,main.player));
313 main.player.notifyEnchantments(new CombatEndEvent(false,combatant));
314 if (!combatant.onWin(main.player)) {
315 LoserScreen.push(main.player,combatant);
317 main.endCombat(oldScreen);
318 return;