mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-03-04 22:50:36 +07:00
Added MonsterComponent and support for dynamic entities
This commit is contained in:
parent
6be326e362
commit
b7778c4398
@ -3,19 +3,25 @@ package com.riiablo.engine;
|
||||
import com.badlogic.ashley.core.Entity;
|
||||
import com.badlogic.ashley.core.PooledEngine;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.riiablo.Riiablo;
|
||||
import com.riiablo.codec.COF;
|
||||
import com.riiablo.codec.excel.MonStats;
|
||||
import com.riiablo.codec.excel.MonStats2;
|
||||
import com.riiablo.codec.excel.Objects;
|
||||
import com.riiablo.engine.component.AnimationComponent;
|
||||
import com.riiablo.engine.component.ClassnameComponent;
|
||||
import com.riiablo.engine.component.CofComponent;
|
||||
import com.riiablo.engine.component.IdComponent;
|
||||
import com.riiablo.engine.component.MonsterComponent;
|
||||
import com.riiablo.engine.component.ObjectComponent;
|
||||
import com.riiablo.engine.component.PositionComponent;
|
||||
import com.riiablo.engine.component.TypeComponent;
|
||||
import com.riiablo.map.DS1;
|
||||
import com.riiablo.map.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Engine extends PooledEngine {
|
||||
@ -38,6 +44,25 @@ public class Engine extends PooledEngine {
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Monster {
|
||||
public static final byte MODE_DT = 0;
|
||||
public static final byte MODE_NU = 1;
|
||||
public static final byte MODE_WL = 2;
|
||||
public static final byte MODE_GH = 3;
|
||||
public static final byte MODE_A1 = 4;
|
||||
public static final byte MODE_A2 = 5;
|
||||
public static final byte MODE_BL = 6;
|
||||
public static final byte MODE_SC = 7;
|
||||
public static final byte MODE_S1 = 8;
|
||||
public static final byte MODE_S2 = 9;
|
||||
public static final byte MODE_S3 = 10;
|
||||
public static final byte MODE_S4 = 11;
|
||||
public static final byte MODE_DD = 12;
|
||||
//public static final byte MODE_GH = 13;
|
||||
public static final byte MODE_XX = 14;
|
||||
public static final byte MODE_RN = 15;
|
||||
}
|
||||
|
||||
public Engine() {
|
||||
super();
|
||||
}
|
||||
@ -65,11 +90,7 @@ public class Engine extends PooledEngine {
|
||||
|
||||
private Entity createDynamicObject(Map map, Map.Zone zone, DS1 ds1, DS1.Object object) {
|
||||
assert object.type == DS1.Object.DYNAMIC_TYPE;
|
||||
PositionComponent positionComponent = createComponent(PositionComponent.class);
|
||||
|
||||
Entity entity = createEntity();
|
||||
entity.add(positionComponent);
|
||||
return entity;
|
||||
return createMonster(map, zone, ds1, object);
|
||||
}
|
||||
|
||||
private Entity createStaticObject(Map map, Map.Zone zone, DS1 ds1, DS1.Object object) {
|
||||
@ -80,7 +101,6 @@ public class Engine extends PooledEngine {
|
||||
Gdx.app.error(TAG, "Unknown static entity id: " + id + "; object=" + object);
|
||||
return null;
|
||||
}
|
||||
//if (!base.Draw) return null;
|
||||
|
||||
TypeComponent typeComponent = createComponent(TypeComponent.class);
|
||||
typeComponent.type = TypeComponent.Type.OBJ;
|
||||
@ -111,4 +131,52 @@ public class Engine extends PooledEngine {
|
||||
entity.getComponent(ClassnameComponent.class).classname = base.Description;
|
||||
return entity;
|
||||
}
|
||||
|
||||
private Entity createMonster(Map map, Map.Zone zone, DS1 ds1, DS1.Object object) {
|
||||
String id = Riiablo.files.obj.getType1(ds1.getAct(), object.id);
|
||||
MonStats.Entry monstats = Riiablo.files.monstats.get(id);
|
||||
if (monstats == null) {
|
||||
Gdx.app.error(TAG, "Unknown dynamic entity id: " + id + "; object=" + object);
|
||||
return null;
|
||||
}
|
||||
|
||||
MonStats2.Entry monstats2 = Riiablo.files.monstats2.get(monstats.MonStatsEx);
|
||||
|
||||
MonsterComponent monsterComponent = createComponent(MonsterComponent.class);
|
||||
monsterComponent.map = map;
|
||||
monsterComponent.zone = zone;
|
||||
monsterComponent.ds1 = ds1;
|
||||
monsterComponent.object = object;
|
||||
monsterComponent.monstats = monstats;
|
||||
monsterComponent.monstats2 = monstats2;
|
||||
|
||||
TypeComponent typeComponent = createComponent(TypeComponent.class);
|
||||
typeComponent.type = TypeComponent.Type.MON;
|
||||
|
||||
CofComponent cofComponent = createComponent(CofComponent.class);
|
||||
cofComponent.token = monstats.Code;
|
||||
cofComponent.mode = monstats.spawnmode.isEmpty() ? Monster.MODE_NU : (byte) Riiablo.files.MonMode.index(monstats.spawnmode);
|
||||
cofComponent.wclass = Riiablo.files.WeaponClass.index(monstats2.BaseW);
|
||||
for (byte i = 0; i < monstats2.ComponentV.length; i++) {
|
||||
String ComponentV = monstats2.ComponentV[i];
|
||||
if (!ComponentV.isEmpty()) {
|
||||
String[] v = StringUtils.remove(ComponentV, '"').split(",");
|
||||
int random = MathUtils.random(0, v.length - 1);
|
||||
cofComponent.component[i] = Riiablo.files.compcode.index(v[random]);
|
||||
}
|
||||
}
|
||||
|
||||
AnimationComponent animationComponent = createComponent(AnimationComponent.class);
|
||||
|
||||
PositionComponent positionComponent = createComponent(PositionComponent.class);
|
||||
|
||||
Entity entity = createEntity();
|
||||
entity.add(typeComponent);
|
||||
entity.add(cofComponent);
|
||||
entity.add(animationComponent);
|
||||
entity.add(positionComponent);
|
||||
entity.add(monsterComponent);
|
||||
entity.getComponent(ClassnameComponent.class).classname = monstats.Id;
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
27
core/src/com/riiablo/engine/component/MonsterComponent.java
Normal file
27
core/src/com/riiablo/engine/component/MonsterComponent.java
Normal file
@ -0,0 +1,27 @@
|
||||
package com.riiablo.engine.component;
|
||||
|
||||
import com.badlogic.ashley.core.Component;
|
||||
import com.badlogic.gdx.utils.Pool;
|
||||
import com.riiablo.codec.excel.MonStats;
|
||||
import com.riiablo.codec.excel.MonStats2;
|
||||
import com.riiablo.map.DS1;
|
||||
import com.riiablo.map.Map;
|
||||
|
||||
public class MonsterComponent implements Component, Pool.Poolable {
|
||||
public Map map;
|
||||
public Map.Zone zone;
|
||||
public DS1 ds1;
|
||||
public DS1.Object object;
|
||||
public MonStats.Entry monstats;
|
||||
public MonStats2.Entry monstats2;
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
map = null;
|
||||
zone = null;
|
||||
ds1 = null;
|
||||
object = null;
|
||||
monstats = null;
|
||||
monstats2 = null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user