1-- Copyright (C) 2007, 2010 - Bit-Blot 2-- 3-- This file is part of Aquaria. 4-- 5-- Aquaria is free software; you can redistribute it and/or 6-- modify it under the terms of the GNU General Public License 7-- as published by the Free Software Foundation; either version 2 8-- of the License, or (at your option) any later version. 9-- 10-- This program is distributed in the hope that it will be useful, 11-- but WITHOUT ANY WARRANTY; without even the implied warranty of 12-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13-- 14-- See the GNU General Public License for more details. 15-- 16-- You should have received a copy of the GNU General Public License 17-- along with this program; if not, write to the Free Software 18-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 20if not v then v = {} end 21if not AQUARIA_VERSION then dofile("scripts/entities/entityinclude.lua") end 22 23-- ================================================================================================ 24-- Z U N N A 25-- ================================================================================================ 26 27-- entity specific 28local STATE_WAIT = 1000 29local STATE_WEAK = 1001 30local STATE_ATTACKPREP = 1002 31local STATE_ATTACK = 1003 32local STATE_RANGEATTACK = 1004 33 34 35-- ================================================================================================ 36-- L O C A L V A R I A B L E S 37-- ================================================================================================ 38 39attackDelay = 2 40rangeAttackDelay = 2 41lunges = 0 42 43-- ================================================================================================ 44-- FUNCTIONS 45-- ================================================================================================ 46 47function init() 48 if getFlag("Battled.Zunna")==1 then 49 entity_delete() 50 else 51 setupBasicEntity( 52 "zunna-body", -- texture 53 12, -- health 54 1, -- manaballamount 55 10, -- exp 56 1, -- money 57 48, -- collideRadius (only used if hit entities is on) 58 STATE_WAIT, -- initState 59 256, -- sprite width 60 256, -- sprite height 61 1, -- particle "explosion" type, 0 = none 62 0, -- 0/1 hit other entities off/on (uses collideRadius) 63 4000 -- updateCull -1: disabled, default: 4000 64 ) 65 end 66 67 entity_initSegments(10, 16, 16, "zunna-tentacle", 68 "zunna-tentacle", 128, 128, 0.05, 0) 69 --createSubEntity("ZunnaArm") 70end 71 72function update(dt) 73 if not(entity_getState()==STATE_DEAD) and not(entity_getState()==STATE_WEAK) then 74 if entity_hasTarget() then 75 if entity_isTargetInRange(64) then 76 entity_hurtTarget(1); 77 entity_pushTarget(250) 78 end 79 end 80 end 81 82 if entity_getState()==STATE_IDLE then 83 if not entity_hasTarget() then 84 entity_findTarget(1000) 85 else 86 if entity_isTargetInRange(250) then 87 entity_moveAroundTarget(dt, 250*5, 0) 88 entity_moveTowardsTarget(dt, 250*2.5) 89 elseif entity_isTargetInRange(1200) then 90 entity_moveTowardsTarget(dt, 1000) 91 else 92 entity_doFriction(dt, 100) 93 end 94 if entity_isTargetInRange(500) then 95 attackDelay = attackDelay - dt 96 if attackDelay <= 0 then 97 if lunges > 2 then 98 --entity_setState(STATE_RANGEATTACK) 99 lunges = 0 100 attackDelay = 2 101 else 102 --entity_setState(STATE_ATTACKPREP) 103 lunges = lunges + 1 104 attackDelay = 4 105 if rangeAttackDelay < 2 then 106 rangeAttackDelay = rangeAttackDelay + 2 107 end 108 end 109 end 110 end 111 end 112 end 113 if not(entity_getState() == STATE_WEAK) then 114 if entity_getHealth() < 10 then 115 entity_setState(STATE_WEAK) 116 end 117 end 118 entity_doCollisionAvoidance(dt, 10, 1) 119 if entity_getState()==STATE_WEAK then 120 entity_doFriction(dt, 1000) 121 end 122 --entity_doSpellAvoidance(dt, 200, 1.5) 123 --entity_rotateToVel(0.1) 124 entity_updateMovement(dt) 125end 126 127function enterState() 128 if entity_getState()==STATE_IDLE then 129 entity_setMaxSpeed(1000) 130 elseif entity_getState()==STATE_WAIT then 131 entity_setMaxSpeed(0) 132 entity_setActivation(1, 80, 320) 133 elseif entity_getState()==STATE_WEAK then 134 --simpleConversation("Zunna_Weak") 135 entity_setActivation(0, 80, 256) 136 elseif entity_getState()==STATE_DEAD then 137 setFlag("Battled.Zunna", 1) 138 setFlag("ZunnaDied", 1) 139 simpleConversation("Zunna_Died") 140 setCanWarp(1) 141 killEntity("Tungar") 142 setFlag("HereticCave1", 6) 143 end 144end 145 146function exitState() 147end 148 149function hitSurface() 150end 151 152function activate() 153 if entity_getState()==STATE_WAIT then 154 simpleConversation("Zunna_Battle") 155 playMusic("Boss") 156 entity_setState(STATE_IDLE) 157 entity_setActivationType(-1) 158 elseif entity_getState()==STATE_WEAK then 159 setFlag("Battled.Zunna", 1) 160 setFlag("ZunnaDied", 0) 161 simpleConversation("Zunna_Capture") 162 setCanWarp(1) 163 killEntity("Tungar") 164 setFlag("HereticCave1", 6) 165 entity_delete() 166 end 167end