3 import flash
.display
.*;
6 import mx
.core
.UIComponent;
7 import org
.sevenchan
.dongs
.Creature
;
8 import org
.sevenchan
.dongs
.creature
.*;
9 import org
.sevenchan
.dongs
.enchantment
.events
.CombatStartEvent
;
10 import org
.sevenchan
.dongs
.enchantment
.events
.ScreenChangedEvent
;
11 import org
.sevenchan
.dongs
.Item
;
12 import org
.sevenchan
.dongs
.Screen;
13 import org
.sevenchan
.dongs
.screens
.*;
14 import org
.sevenchan
.dongs
.Town
;
15 import org
.sevenchan
.dongs
.ui
.*;
20 [Frame
(factoryClass
="Preloader",backgroundColor
=0x666666,frames
=10)]
21 [SWF
(width
=800,height
=600,frameRate
=60,backgroundColor
="#666666")]
23 public class AdventureController
extends Sprite
26 private const default_bg_color
:uint = 0x333333;
27 private var currentBGColor
:uint = default_bg_color
;
28 public var bodyPartsDialog
:org
.sevenchan
.dongs
.frmBodyPartsPool
= new org
.sevenchan
.dongs
.frmBodyPartsPool
;
29 private var bgshape
:Sprite;
31 private var currentScreen
:Screen;
32 private var combatScreen
:Screen;
33 private var btnNewGame
:SexButton
;
34 private var btnLoadSaveGame
:SexButton
;
35 private var btnExportGame
:SexButton
;
36 private var btnImportGame
:SexButton
;
37 private var btnDebugMenu
:SexButton
;
38 private var btnAppearance
:SexButton
;
39 private var btnAction
:Array;
41 private var pnlMain
:SexPanel
;
42 private var pnlStats
:SexPanel
;
44 private var statXP
:Statistic
;
45 private var statStrength
:Statistic
;
46 private var statSpeed
:Statistic
;
47 private var statIntellect
:Statistic
;
48 private var statSensitivity
:Statistic
;
49 private var statLust
:Statistic
;
51 private var statMana
:Statistic
;
52 public var statHP
:Statistic
;
53 private var statGold
:TextField;
55 private var statsAreSetUp
:Boolean = false;
57 public var player
:Player
;
59 public static var screenQueue
:Queue
= new Queue
();
61 public function AdventureController
(appl
:Main
):void
65 player
= new Player
(this);
69 addEventListener
(Event.ADDED_TO_STAGE
, init
);
72 public static function init
(app
:Main
):void
74 var ui
:UIComponent = new UIComponent();
75 ui
.addChild
(new AdventureController
(app
));
79 private function init
(e
:Event = null):void
83 removeEventListener
(Event.ADDED_TO_STAGE
, init
);
87 var toprow
:Number = 600 - 549;
90 //stage.opaqueBackground = 0x666666;
92 var txtHeader
:TextField = new TextField();
93 var tf
:TextFormat = new TextFormat();
96 txtHeader
.htmlText
= "ADVENTURE OF THE SEVEN LEAVES <b>RELEASE 28</b>";
97 txtHeader
.setTextFormat
(tf
);
98 txtHeader
.autoSize
= "left";
103 // Top row of buttons
104 btnNewGame
= addButton
("New Game", 100, y
, toprow
);
106 btnNewGame
.addEventListener
(MouseEvent.CLICK
, onNewGame
);
107 btnLoadSaveGame
= addButton
("Load Game", 100, y
, toprow
);
109 btnLoadSaveGame
.addEventListener
(MouseEvent.CLICK
, onLoadOrSave
);
110 btnImportGame
= addButton
("Import Game", 100, y
, toprow
);
112 btnImportGame
.addEventListener
(MouseEvent.CLICK
, onImport
);
113 btnExportGame
= addButton
("Export Game", 100, y
, toprow
);
115 btnExportGame
.addEventListener
(MouseEvent.CLICK
, onExport
);
116 btnDebugMenu
= addButton
("Debug Menu", 100, y
, toprow
);
118 btnDebugMenu
.addEventListener
(MouseEvent.CLICK
, onDebugMenu
);
119 btnAppearance
= addButton
("Appearance", 100, y
, toprow
);
120 btnAppearance
.addEventListener
(MouseEvent.CLICK
, onAppearance
);
123 pnlMain
= addPanel
("", 464.5, 618.5, 167.75, 56.75);
124 pnlStats
= addPanel
("", 464.5, 144.9, 15.75, 56.75);
126 // Second row of buttons
127 btnAction
= new Array();
128 for (var i
:int = 0; i
< 12; i
++)
130 var btn
:SexButton
= addButton
((i
+ 1).toString
(), 100, 16 + ((i
% 6) * 129.2), 561 + (Math.round
(i
/ 12) * 32));
132 btn
.addEventListener
(MouseEvent.CLICK
, onActionClick
);
135 setScreen
(new StartupScreen
());
138 public function onDebugMenu
(lolno
:MouseEvent):void
140 setScreen
(new DebugScreen
());
143 public function showBodyPartSelector
(show
:Boolean):void
145 app
.showBodyParts
(show
);
147 updateScreen
(currentScreen
);
150 public function showCreatureViewer
(show
:Boolean):void
152 app
.showCreatureViewer
(show
);
154 updateScreen
(currentScreen
);
157 public function setCheatMode
(val
:Boolean):void
159 statHP
.showCheatButtons
(val
);
160 statXP
.showCheatButtons
(val
);
161 statIntellect
.showCheatButtons
(val
);
162 statLust
.showCheatButtons
(val
);
163 statMana
.showCheatButtons
(val
);
164 statSensitivity
.showCheatButtons
(val
);
165 statSpeed
.showCheatButtons
(val
);
166 statStrength
.showCheatButtons
(val
);
169 private function onAppearance
(e
:MouseEvent):void
171 setScreen
(new AppearanceScreen
());
174 private function onNewGame
(e
:MouseEvent):void
176 player
= new Player
(this);
177 player
.setMain
(this);
178 app
.bodyparts
.init
(player
);
179 app
.creatures
.init
(player
);
180 setScreen
(new NewGameScreen
());
183 private function onImport
(e
:MouseEvent):void
185 player
= new Player
(this);
186 player
.setMain
(this);
190 private function onExport
(e
:MouseEvent):void
195 private function onLoadOrSave
(e
:MouseEvent):void
197 if (!currentScreen
.loadOrSaveButton
)
199 setScreen
(new LoadSaveScreen
(true));
203 setScreen
(new LoadSaveScreen
(false));
207 public function onPlayerLoaded
():void
210 setScreen
(player
.currentTown
);
213 public function addToStatsPanel
(stat
:Statistic
):void
215 pnlStats
.addToStack
(stat
);
216 pnlStats
.arrangeStack
();
219 public function remFromStatsPanel
(stat
:Statistic
):void
221 pnlStats
.delFromStack
(stat
);
222 pnlStats
.arrangeStack
();
225 public function setupStatsPanel
():void
227 pnlStats
.stackMode
(); // Remove textField.
228 pnlStats
.addToStack
(new StackHeader
("STATS"));
229 statXP
= new Statistic
("Experience", "How far you are from levelling up", true, setXP
);
230 pnlStats
.addToStack
(statXP
);
231 statStrength
= new Statistic
("Strength", "How much power your attacks will have.", false, setStrength
);
232 pnlStats
.addToStack
(statStrength
);
233 statSpeed
= new Statistic
("Speed", "How fast you are; Affects dodging and catching opponents.", false, null);
234 pnlStats
.addToStack
(statSpeed
);
235 statIntellect
= new Statistic
("Intellect", "Perceptiveness. Allows you to sense impending danger and figure out puzzles easier.", false, null);
236 pnlStats
.addToStack
(statIntellect
);
237 statSensitivity
= new Statistic
("Sensitivity", "The more sensitive you are, the faster your lust rises. However, lack of sensation means you cannot masturbate.", false, null);
238 pnlStats
.addToStack
(statSensitivity
);
239 statLust
= new Statistic
("Lust", "How horny you are right now.", false, null);
240 pnlStats
.addToStack
(statLust
);
242 pnlStats
.addToStack
(new StackHeader
("COMBAT"));
243 statHP
= new Statistic
("HP", "Health left.", false, null);
244 pnlStats
.addToStack
(statHP
);
245 statMana
= new Statistic
("Mana", "Magic stuff", false, null);
246 pnlStats
.addToStack
(statMana
);
248 pnlStats
.addToStack
(new StackHeader
("GOLD"));
249 statGold
= new TextField();
250 pnlStats
.addToStack
(statGold
);
251 var tf
:TextFormat = new TextFormat();
255 tf
.align
= TextFormatAlign.CENTER
;
256 statGold
.setTextFormat
(tf
);
257 statGold
.defaultTextFormat
= tf
;
259 pnlStats
.arrangeStack
();
260 statsAreSetUp
= true;
265 private function setGold
(value
:int):void
270 private function setHP
(value
:int):void
275 private function setIntellect
(value
:int):void
277 player
.intellect
= value
;
280 private function setLust
(value
:int):void
285 private function setMana
(value
:int):void
290 private function setSensitivity
(value
:int):void
292 player
.sensitivity
= value
;
295 private function setSpeed
(value
:int):void
297 player
.speed
= value
;
300 private function setStrength
(value
:int):void
302 player
.strength
= value
;
305 private function setXP
(value
:int):void
310 private function setScreen
(screen
:Screen):void
312 //trace("setscreen ",screen);
317 if (combatScreen
== null)
318 screen
= player
.currentTown
;
320 screen
= combatScreen
;
323 screen
= new StartupScreen
();
326 screen
= new StartupScreen
();
327 currentScreen
= screen
;
328 currentScreen
.setMain
(this);
329 currentScreen
.processButtonPress
(-1);
332 private function onActionClick
(e
:MouseEvent):void
334 var clicked
:SexButton
= e
.target
as SexButton
;
335 for (var i
:int = 0; i
< 12; i
++)
337 if (clicked
== btnAction
[i
])
339 var done
:Boolean = currentScreen
.processButtonPress
(i
);
340 //trace(currentScreen,done);
343 setScreen
(AdventureController
.screenQueue
.read
());
350 public function updateScreen
(screen
:Screen):void
352 pnlMain
.visible
= visible
;
353 pnlStats
.visible
= visible
;
354 var btns
:Array = screen
.getButtons
();
355 for (var i
:int = 0; i
< 12; i
++)
357 var btn
:SexButton
= (btnAction
[i
] as SexButton
);
358 btn
.visible
= (btns
[i
] != "") && visible
;
359 btn
.setText
(btns
[i
]);
361 this.btnAppearance
.visible
= screen
.appearanceButton
&& visible
;
362 this.btnDebugMenu
.visible
= screen
.debugMenuButton
&& visible
&& player
!= null;
363 this.btnExportGame
.visible
= screen
.exportGameButton
&& visible
;
364 this.btnLoadSaveGame
.setText
((screen
.loadOrSaveButton
) ? "Save Game" : "Load Game");
365 this.btnLoadSaveGame
.visible
= visible
&& screen
.showLoadOrSaveButton
;
366 this.btnNewGame
.visible
= screen
.newGameButton
&& visible
;
367 this.btnImportGame
.visible
= screen
.importGameButton
&& visible
;
369 this.pnlMain
.text
= screen
.getScreenText
();
372 player
.notifyEnchantments
(new ScreenChangedEvent
());
373 player
.addLust
(screen
.lustCost
);
377 public function refreshStats
():void
379 if (player
.level
== 0)
381 player
.levelUp
(true);
385 statXP
.setMaxAndValue
(player
.maxXP
, player
.XP
, false);
386 statStrength
.setMaxAndValue
(100, player
.strength
, false);
387 statSpeed
.setMaxAndValue
(100, player
.speed
, false);
388 statIntellect
.setMaxAndValue
(100, player
.intellect
, false);
389 statSensitivity
.setMaxAndValue
(100, player
.sensitivity
, false);
390 statLust
.setMaxAndValue
(100, player
.lust
, false);
392 statHP
.setMaxAndValue
(player
.maxHP
, player
.HP
, false);
393 statMana
.setMaxAndValue
(100, player
.mana
, false);
394 statGold
.text
= player
.gold
+ "";
397 private function addButton
(label
:String, size
:Number, x
:Number, y
:Number):SexButton
399 var btn
:SexButton
= new SexButton
(size
, label
);
402 btn
.y
= y
- btn
.height
;
406 private function addPanel
(text
:String, h
:Number, w
:Number, x
:Number, y
:Number):SexPanel
408 var btn
:SexPanel
= new SexPanel
(text
);
416 public function onResize
(h
:Number, w
:Number, measuredHeight
:Number, measuredWidth
:Number):void
418 var originalPanelHeightPCT
:Number = 464.5 / 600;
419 //pnlStats = addPanel("", 464.5, 144.9, 15.75, 56.75);
420 //pnlMain = addPanel("", 464.5, 618.5, 167.75, 56.75);
422 pnlStats
.height
= pnlMain
.height
= (464.5 / 600) * h
;
423 pnlStats
.width
= (144.9 / 800) * w
;
424 pnlStats
.x
= (15.75 / 800) * w
;
425 pnlStats
.y
= (56.75 / 600) * h
;
427 pnlMain
.width
= (618.5 / 800) * w
;
428 pnlMain
.x
= (167.75 / 800) * w
;
429 pnlMain
.y
= (56.75 / 600) * h
;
433 var xOffset
:Number = (16 / 800) * w
;
434 var yOffset
:Number = (531 / 600) * h
; //(561 / 600) * h;
435 var bHeightPadding
:Number = (32 / 600) * h
;
436 var bWidthPadding
:Number = (129.2 / 800) * w
;
437 var bHeight
:Number = (30 / 600) * h
;
438 var bWidth
:Number = (100 / 800) * w
;
439 for (var i
:int = 0; i
< 12; i
++)
441 //var btn:SexButton = addButton((i + 1).toString(), 100, 16 + ((i % 6) * 129.2), 561 + (Math.round(i / 12) * 32));
442 btnAction
[i
].height
= bHeight
;
443 btnAction
[i
].width
= bWidth
;
444 btnAction
[i
].x
= xOffset
+ ((i
% 6) * bWidthPadding
);
445 btnAction
[i
].y
= yOffset
+ (Math.round
(i
/ 12) * bHeightPadding
);
448 // Top row of buttons
449 xOffset
= (129.2 / 800) * w
;
450 var toprow
:Number = (21 / 600) * h
; // 51 - 21 = 30
451 var x
:Number = (16 / 800) * w
;
452 btnNewGame
.width
= bWidth
;
453 btnNewGame
.height
= bHeight
;
454 btnNewGame
.y
= toprow
;
458 btnLoadSaveGame
.width
= bWidth
;
459 btnLoadSaveGame
.height
= bHeight
;
460 btnLoadSaveGame
.y
= toprow
;
461 btnLoadSaveGame
.x
= x
;
464 btnImportGame
.width
= bWidth
;
465 btnImportGame
.height
= bHeight
;
466 btnImportGame
.y
= toprow
;
470 btnExportGame
.width
= bWidth
;
471 btnExportGame
.height
= bHeight
;
472 btnExportGame
.y
= toprow
;
476 btnDebugMenu
.width
= bWidth
;
477 btnDebugMenu
.height
= bHeight
;
478 btnDebugMenu
.y
= toprow
;
482 btnAppearance
.width
= bWidth
;
483 btnAppearance
.height
= bHeight
;
484 btnAppearance
.y
= toprow
;
488 private function initBG
():void
490 bgshape
= new Sprite();
491 bgshape
.graphics
.clear
();
492 bgshape
.graphics
.beginFill
(currentBGColor
);
493 bgshape
.graphics
.drawRect
(0, 0, stage
.stageWidth
, stage
.stageHeight
);
494 addChildAt
(bgshape
, 0);
495 stage
.addEventListener
(Event.RESIZE
, resizeBGWithStage
);
498 private function redrawBG
():void
500 bgshape
.graphics
.beginFill
(currentBGColor
);
501 bgshape
.graphics
.drawRect
(0, 0, stage
.stageWidth
, stage
.stageHeight
);
504 private function resizeBGWithStage
(e
:Event):void
508 bgshape
.width
= stage
.stageWidth
;
509 bgshape
.height
= stage
.stageHeight
;
516 public function showInventory
(item
:Item
= null):void
518 setScreen
(new InventoryScreen
(item
));
521 public function startRape
(oldScreen
:Screen, combatant
:Creature
, playerInitiated
:Boolean = false):void
523 if (!(oldScreen
is CombatScreen
))
525 if (!combatant
.staticStats
)
527 combatant
._level
= Math.max
(1, player
.level
+ MathUtils
.rand
(-2, 2));
528 combatant
._strength
= Math.max
(1, player
.strength
+ MathUtils
.rand
(-2, 2));
530 combatant
.HP
= combatant
.maxHP
;
531 combatant
.mana
= combatant
.maxMana
;
533 combatant
.notifyEnchantments
(new CombatStartEvent
(player
));
534 player
.notifyEnchantments
(new CombatStartEvent
(combatant
));
536 if (combatant
.tryRape
(player
))
538 combatScreen
= new Rape
(combatant
);
539 setScreen
(combatScreen
);
540 currentBGColor
= 0x330000;
542 updateScreen
(combatScreen
);
546 if (!(oldScreen
is CombatScreen
))
548 startCombat
(oldScreen
, combatant
, false);
553 public function startCombat
(oldScreen
:Screen, combatant
:Creature
, playerInitiated
:Boolean = false):void
555 if (!combatant
.staticStats
)
557 if (player
.level
< 5)
559 combatant
._level
= Math.max
(1, player
.level
+ MathUtils
.rand
(-2, 0));
560 combatant
._strength
= Math.max
(1, player
.strength
+ MathUtils
.rand
(-2, 0));
564 combatant
._level
= Math.max
(1, player
.level
+ MathUtils
.rand
(-2, 2));
565 combatant
._strength
= Math.max
(1, player
.strength
+ MathUtils
.rand
(-2, 2));
568 combatant
.HP
= combatant
.maxHP
;
569 combatant
.mana
= combatant
.maxMana
;
571 combatant
.notifyEnchantments
(new CombatStartEvent
(player
));
572 player
.notifyEnchantments
(new CombatStartEvent
(combatant
));
573 combatScreen
= new CombatScreen
(oldScreen
, combatant
, playerInitiated
);
574 setScreen
(combatScreen
);
575 currentBGColor
= 0x330000;
579 public function endCombat
(oldScreen
:Screen):void
582 currentBGColor
= default_bg_color
;
586 public function setTown
(t
:Town
):void
588 player
.currentTown
= t
;