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
;
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;
40 // Attack Items Abilities Run Forfeit
42 // Punch Kick Headbutt
43 public function CombatScreen
(prevScrn
:Screen,c
:Creature
,playerInitiated
:Boolean)
47 this.playerInitiated
= playerInitiated
;
51 override public function processButtonPress
(id
:int):Boolean
55 if (main
.player
.getInterested
(combatant
))
60 if (id
== -1 && act
=="")
63 combatant
.onCombatInit
(main
.player
);
65 tryAttack
(main
.player
, combatant
);
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>";
76 tryAttack
(main
.player
, combatant
);
82 if (main
.player
.HP
<=0)
88 AdventureController
.screenQueue
.write
(new InventoryScreen
());
91 if ("abilities" == act
) {
92 return abilitiesMenu
(id
);
97 private function mainMenu
(id
:int):Boolean {
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
())
106 setButton
(4, "Forfeit");
107 if (combatant
.getRapable
())
108 setButton
(5, "Rape");
110 setButton
(0, Enchantment
.getLockoutEffectText
(main
.player
));
115 var bypassNotification
:Boolean = passAction
== -3;
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) {
125 combatant
.yourMove
(this, main
.player
);
127 passAction
= -3; // Just in case we're forcing attack
129 mainMenu
(passAction
);
132 tryAttack
(main
.player
, combatant
);
139 if (main
.player
.HP
<=0)
144 if (main
.player
.lust
>=100)
152 AdventureController
.screenQueue
.write
(new InventoryScreen
());
157 return abilitiesMenu
( -1);
160 if (main
.player
.speed
- combatant
.speed
> -1) {
161 text
= "<p>You successfully manage to get away!</p>";
162 main
.endCombat
(oldScreen
);
164 text
= "<p>You're unable to get away!</p>";
165 main
.player
.notifyEnchantments
(new CombatTurnEvent
(this,combatant
));
175 main
.startRape
(this, combatant
, true);
182 private function abilitiesMenu
(id
:int):Boolean {
184 setButton
(0, "CANCEL");
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
);
197 setButton
(i
, ability
.label
);
198 text
+= "<li><b>" + ability
.name
+ "</b> - " + ability
.description
+ "</li>";
204 text
+= "<p><i>You don't have any abilities at the moment.</i></p>";
212 return processButtonPress
(-1);
214 (ab
[id
- 1] as Ability
).activate
(main
.player
, combatant
);
215 main
.player
.notifyEnchantments
(new CombatTurnEvent
(this,combatant
));
221 if (main
.player
.HP
<=0)
226 if (main
.player
.lust
>=100)
228 main
.startRape
(this,combatant
,true);
235 override public function getScreenText
():String
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
);
260 arm
.weapon
.onGoodAttack
(from
, to
);
262 if(limbMissed
(arm
,from
,to
))
263 arm
.onFailedAttack
(from
,to
);
265 arm
.onGoodAttack
(from
, to
);
267 to
.yourMove
(this,main
.player
);
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
);
275 leg
.onGoodAttack
(from
,to
);
276 to
.yourMove
(this,main
.player
);
281 text
= "<p>You don't have arms or legs, so you can't attack!</p>";
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
);
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
);