feat: implement GameLogic.executeRequest

This commit is contained in:
punchready 2021-05-01 23:06:22 +02:00
parent 3b286b4667
commit bebe721788
5 changed files with 60 additions and 25 deletions

View File

@ -4,9 +4,10 @@
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>
<option name="delegatedBuild" value="true" />
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" /> <option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="#JAVA_HOME" />
<option name="modules"> <option name="modules">
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />

View File

@ -13,12 +13,6 @@ public class CharacterEvent extends Event {
public Integer amount = null; public Integer amount = null;
public StoneType stoneType = null; public StoneType stoneType = null;
@Override
public CharacterEvent type(EventType type) {
this.type = type;
return this;
}
public CharacterEvent setOriginEntity(EntityID originEntity) { public CharacterEvent setOriginEntity(EntityID originEntity) {
this.originEntity = originEntity; this.originEntity = originEntity;
return this; return this;

View File

@ -9,12 +9,6 @@ public class EntityEvent extends Event {
public IntVector2 targetField = null; public IntVector2 targetField = null;
public Integer amount = null; public Integer amount = null;
@Override
public EntityEvent type(EventType type) {
this.type = type;
return this;
}
public EntityEvent setTargetEntity(EntityID targetEntity) { public EntityEvent setTargetEntity(EntityID targetEntity) {
this.targetEntity = targetEntity; this.targetEntity = targetEntity;
return this; return this;

View File

@ -1,11 +1,12 @@
package uulm.teamname.marvelous.gamelibrary.gamelogic; package uulm.teamname.marvelous.gamelibrary.gamelogic;
import uulm.teamname.marvelous.gamelibrary.Tuple; import uulm.teamname.marvelous.gamelibrary.Tuple;
import uulm.teamname.marvelous.gamelibrary.events.Event; import uulm.teamname.marvelous.gamelibrary.events.*;
import uulm.teamname.marvelous.gamelibrary.requests.CharacterRequest;
import uulm.teamname.marvelous.gamelibrary.requests.Request; import uulm.teamname.marvelous.gamelibrary.requests.Request;
import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
/** Contains game logic handling. */ /** Contains game logic handling. */
class GameLogic { class GameLogic {
@ -14,18 +15,63 @@ class GameLogic {
* @return The list of resulting events * @return The list of resulting events
*/ */
public static ArrayList<Event> executeRequest(Request request) { public static ArrayList<Event> executeRequest(Request request) {
ArrayList<Event> result = new ArrayList<Event>(); ArrayList<Event> result = new ArrayList<>();
//TODO: implement GameLogic.executeRequest switch(request.type) {
case MeleeAttackRequest, RangedAttackRequest -> {
CharacterRequest data = (CharacterRequest)request;
result.add(new CharacterEvent()
.setOriginEntity(data.originEntity)
.setTargetEntity(data.targetEntity)
.setOriginField(data.originField)
.setTargetField(data.targetField)
.setAmount(data.value)
.type(request.type == RequestType.MeleeAttackRequest ? EventType.MeleeAttackEvent : EventType.RangedAttackEvent));
result.add(new EntityEvent()
.setTargetEntity(data.originEntity)
.setTargetField(data.originField)
.setAmount(1)
.type(EventType.ConsumedAPEvent));
result.add(new EntityEvent()
.setTargetEntity(data.targetEntity)
.setTargetField(data.targetField)
.setAmount(data.value)
.type(EventType.TakenDamageEvent));
}
case MoveRequest -> {
CharacterRequest data = (CharacterRequest)request;
result.add(new CharacterEvent()
.setOriginEntity(data.originEntity)
.setOriginField(data.originField)
.setTargetField(data.targetField)
.type(EventType.MoveEvent));
result.add(new EntityEvent()
.setTargetEntity(data.originEntity)
.setTargetField(data.targetField) //when this event gets handled, the character already moved to the target field
.setAmount(1)
.type(EventType.ConsumedMPEvent));
}
case ExchangeInfinityStoneRequest, UseInfinityStoneRequest -> {
CharacterRequest data = (CharacterRequest)request;
result.add(new CharacterEvent()
.setOriginEntity(data.originEntity)
.setTargetEntity(data.targetEntity)
.setOriginField(data.originField)
.setTargetField(data.targetField)
.setStone(data.stoneType)
.type(request.type == RequestType.ExchangeInfinityStoneRequest ? EventType.ExchangeInfinityStoneEvent : EventType.UseInfinityStoneEvent));
result.add(new EntityEvent()
.setTargetEntity(data.originEntity)
.setTargetField(data.originField)
.setAmount(1)
.type(EventType.ConsumedAPEvent));
/* Example Code: }
switch (event.type) { case DisconnectRequest -> {
case EventType.MeleeAttack: result.add(new GameEvent()
result.add(Event.Construct(EventType.APReduced, event.sourceEntity, event.ap)); .type(EventType.DisconnectEvent));
result.add(Event.Construct(EventType.DamageTaken, event.targetEntity, event.value)); }
break;
} }
*/
return result; return result;
} }