46 lines
1.6 KiB
Java
46 lines
1.6 KiB
Java
package com.example.systems;
|
|
|
|
import java.util.Random;
|
|
|
|
import com.example.components.Attack;
|
|
import com.example.components.Battle;
|
|
import com.example.components.BattleWin;
|
|
import com.example.components.Hero;
|
|
import com.example.components.Squad;
|
|
import com.example.components.Stats;
|
|
import com.example.ecs.Entity;
|
|
import com.example.ecs.Registry;
|
|
import com.example.ecs.System;
|
|
|
|
public class WinSystem extends System {
|
|
|
|
public WinSystem(Registry registry) {
|
|
super(registry);
|
|
}
|
|
|
|
public void run() {
|
|
for (var battleEntity : registry.getWithComponents(Battle.class)) {
|
|
var battle = registry.getComponent(battleEntity, Battle.class);
|
|
|
|
var squad1 = registry.getComponent(battle.squad1(), Squad.class);
|
|
var squad2 = registry.getComponent(battle.squad2(), Squad.class);
|
|
|
|
Entity battleWinEntity = new Entity();
|
|
if (!squad1.isActive() && !squad2.isActive()) {
|
|
BattleWin battleWin = new BattleWin(battle.squad1(), battle.squad2(), true);
|
|
registry.addComponent(battleWinEntity, battleWin);
|
|
} else if (!squad1.isActive()) {
|
|
BattleWin battleWin = new BattleWin(battle.squad2(), battle.squad1(), false);
|
|
registry.addComponent(battleWinEntity, battleWin);
|
|
} else if (!squad2.isActive()) {
|
|
BattleWin battleWin = new BattleWin(battle.squad1(), battle.squad2(), false);
|
|
registry.addComponent(battleWinEntity, battleWin);
|
|
}
|
|
|
|
if (!squad1.isActive() || !squad2.isActive()) {
|
|
registry.remove(battleEntity);
|
|
}
|
|
}
|
|
}
|
|
}
|