forked from CuteLunaMoon/Survival-Pixel-Dungeon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMosquitoSwarm.java
167 lines (134 loc) · 4.67 KB
/
MosquitoSwarm.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2018 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.actors.mobs;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Burning;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Corruption;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Poison;
import com.shatteredpixel.shatteredpixeldungeon.effects.Pushing;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfHealing;
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
import com.shatteredpixel.shatteredpixeldungeon.levels.features.Door;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.SwarmSprite;
import com.watabou.utils.Bundle;
import com.watabou.utils.Random;
import java.util.ArrayList;
public class MosquitoSwarm extends Mob {
{
spriteClass = SwarmSprite.class;
HP = HT = 35;
defenseSkill = 5;
EXP = 3;
maxLvl = 9;
flying = true;
loot = new PotionOfHealing();
lootChance = 0.1667f; //by default, see rollToDropLoot()
}
private static final float SPLIT_DELAY = 1f;
int generation = 0;
private static final String GENERATION = "generation";
@Override
public void storeInBundle( Bundle bundle ) {
super.storeInBundle( bundle );
bundle.put( GENERATION, generation );
}
@Override
public void restoreFromBundle( Bundle bundle ) {
super.restoreFromBundle( bundle );
generation = bundle.getInt( GENERATION );
if (generation > 0) EXP = 0;
}
@Override
public int attackProc( Char enemy, int damage ) {
damage = super.attackProc( enemy, damage );
int reg = Math.min( damage, HT - HP );
if (reg > 0) {
HP += reg;
sprite.emitter().burst( Speck.factory( Speck.HEALING ), 1 );
}
return damage;
}
@Override
public int damageRoll() {
return Random.NormalIntRange( 1, 4 );
}
@Override
public int defenseProc( Char enemy, int damage ) {
if (HP >= damage + 2) {
ArrayList<Integer> candidates = new ArrayList<>();
boolean[] solid = Dungeon.level.solid;
int[] neighbours = {pos + 1, pos - 1, pos + Dungeon.level.width(), pos - Dungeon.level.width()};
for (int n : neighbours) {
if (!solid[n] && Actor.findChar( n ) == null) {
candidates.add( n );
}
}
if (candidates.size() > 0) {
MosquitoSwarm clone = split();
clone.HP = (HP - damage) / 2;
clone.pos = Random.element( candidates );
clone.state = clone.HUNTING;
if (Dungeon.level.map[clone.pos] == Terrain.DOOR) {
Door.enter( clone.pos );
}
GameScene.add( clone, SPLIT_DELAY );
Actor.addDelayed( new Pushing( clone, pos, clone.pos ), -1 );
HP -= clone.HP;
}
}
return super.defenseProc(enemy, damage);
}
@Override
public int attackSkill( Char target ) {
return 10;
}
private MosquitoSwarm split() {
MosquitoSwarm clone = new Swarm();
clone.generation = generation + 1;
clone.EXP = 0;
if (buff( Burning.class ) != null) {
Buff.affect( clone, Burning.class ).reignite( clone );
}
if (buff( Poison.class ) != null) {
Buff.affect( clone, Poison.class ).set(2);
}
if (buff(Corruption.class ) != null) {
Buff.affect( clone, Corruption.class);
}
return clone;
}
@Override
public void rollToDropLoot() {
lootChance = 1f/(6 * (generation+1) );
lootChance *= (5f - Dungeon.LimitedDrops.SWARM_HP.count) / 5f;
super.rollToDropLoot();
}
@Override
protected Item createLoot(){
Dungeon.LimitedDrops.SWARM_HP.count++;
return super.createLoot();
}
}