Skip to content

Commit

Permalink
#139, wont load yet
Browse files Browse the repository at this point in the history
  • Loading branch information
NeumimTo committed Apr 26, 2020
1 parent ce69d5a commit c59ceb0
Show file tree
Hide file tree
Showing 12 changed files with 374 additions and 41 deletions.
140 changes: 140 additions & 0 deletions API/src/main/java/cz/neumimto/rpg/api/skills/RepeatingSkill.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package cz.neumimto.rpg.api.skills;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigException;
import cz.neumimto.rpg.api.Rpg;
import cz.neumimto.rpg.api.effects.EffectBase;
import cz.neumimto.rpg.api.effects.EffectService;
import cz.neumimto.rpg.api.effects.IEffect;
import cz.neumimto.rpg.api.effects.IEffectContainer;
import cz.neumimto.rpg.api.entity.players.IActiveCharacter;
import cz.neumimto.rpg.api.skills.mods.SkillContext;
import cz.neumimto.rpg.api.skills.mods.SkillExecutorCallback;
import cz.neumimto.rpg.api.skills.tree.SkillTree;
import cz.neumimto.rpg.api.skills.types.ActiveSkill;
import cz.neumimto.rpg.api.skills.utils.SkillLoadingErrors;

import javax.inject.Inject;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public class RepeatingSkill extends ActiveSkill {

@Inject
private EffectService effectService;

@Override
public WrappedSkill.WrappedSkillData constructSkillData() {
return new RepeatingSkillData(getId(), super.constructSkillData());
}

@Override
public <T extends SkillData> void loadSkillData(T skillData, SkillTree context, SkillLoadingErrors errors, Config c) {
RepeatingSkillData data = (RepeatingSkillData) skillData;
data.period = c.getLong("Repeat-period");
try {
data.maxDuartion = c.getLong("Repeat-maxDuration");
} catch (ConfigException ignored) {
data.maxDuartion = -1;
}

Config inner = c.getConfig("Parent");
data.getSkill().loadSkillData(skillData, context, errors, inner);
}

@Override
public void cast(IActiveCharacter character, PlayerSkillContext info, SkillContext skillContext) {
RepeatingSkillData skillData = (RepeatingSkillData) info.getSkillData();

RepeatingSkillEffect repeatingSkillEffect = new RepeatingSkillEffect(skillData, character);
effectService.addEffect(repeatingSkillEffect, this);

skillContext.next(character, info, skillContext.result(SkillResult.OK));
}


public static class RepeatingSkillData extends WrappedSkill.WrappedSkillData {
public long period;
public long maxDuartion;

public RepeatingSkillData(String skill, SkillData wrapped) {
super(skill, wrapped);
}
}

public class RepeatingSkillEffect extends EffectBase implements IEffectContainer {

private final RepeatingSkillData skillData;
private final IActiveCharacter character;
private final PlayerSkillContext info;
private final RepeatingNotificationSkillExecutor executor;
private final SkillContext skillContext;

public RepeatingSkillEffect(RepeatingSkillData skillData, IActiveCharacter character) {
super("repeating_" + skillData.getSkillId(), character);
this.skillData = skillData;
this.character = character;
this.info = character.getSkillInfo(skillData.getWrapped().getSkill());
setDuration(skillData.maxDuartion);
setPeriod(skillData.period);
executor = new RepeatingNotificationSkillExecutor(this);
skillContext = new SkillContext(RepeatingSkill.this, info);
}

public RepeatingSkillData getSkillData() {
return skillData;
}

@Override
public void onTick(IEffect self) {
Rpg.get().getSkillService().executeSkill(character, info, skillContext, executor);
}


@Override
public Object getStackedValue() {
return null;
}

@Override
public void setStackedValue(Object o) {

}

@Override
public Set<RepeatingSkillEffect> getEffects() {
return new HashSet<>(Collections.singletonList(this));
}


@Override
public RepeatingSkillEffect constructEffectContainer() {
return this;
}

}


static class RepeatingNotificationSkillExecutor extends SkillExecutorCallback {

private RepeatingSkillEffect repeatingSkillEffect;

public RepeatingNotificationSkillExecutor(RepeatingSkillEffect repeatingSkillEffect) {
this.repeatingSkillEffect = repeatingSkillEffect;
}

@Override
public void doNext(IActiveCharacter character, PlayerSkillContext info, SkillContext skillResult) {
switch (skillResult.getResult()) {
case NO_MANA:
case NO_HP:
repeatingSkillEffect.setDuration(0);
break;
default:
skillResult.resetCursor();
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cz.neumimto.rpg.api.entity.players.IActiveCharacter;
import cz.neumimto.rpg.api.gui.ISkillTreeInterfaceModel;
import cz.neumimto.rpg.api.skills.mods.SkillContext;
import cz.neumimto.rpg.api.skills.mods.SkillExecutorCallback;
import cz.neumimto.rpg.api.skills.scripting.ScriptSkillModel;
import cz.neumimto.rpg.api.skills.tree.SkillTree;
Expand All @@ -24,6 +25,9 @@ public interface SkillService {

void executeSkill(IActiveCharacter character, PlayerSkillContext esi, SkillExecutorCallback callback);

void executeSkill(IActiveCharacter character, PlayerSkillContext esi, SkillContext context,
SkillExecutorCallback callback);

PlayerSkillContext invokeSkillByCombo(String combo, IActiveCharacter character);

void reloadSkillTrees();
Expand Down
132 changes: 132 additions & 0 deletions API/src/main/java/cz/neumimto/rpg/api/skills/WrappedSkill.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package cz.neumimto.rpg.api.skills;

import com.typesafe.config.Config;
import cz.neumimto.rpg.api.ResourceLoader;
import cz.neumimto.rpg.api.entity.players.IActiveCharacter;
import cz.neumimto.rpg.api.skills.mods.ActiveSkillPreProcessorWrapper;
import cz.neumimto.rpg.api.skills.mods.SkillContext;
import cz.neumimto.rpg.api.skills.tree.SkillTree;
import cz.neumimto.rpg.api.skills.utils.SkillLoadingErrors;

import java.util.List;
import java.util.Set;

public class WrappedSkill implements ISkill {

private ISkill inner;
private String catalogId;

public WrappedSkill() {
ResourceLoader.Skill sk = this.getClass().getAnnotation(ResourceLoader.Skill.class);
if (sk != null) {
catalogId = sk.value().toLowerCase();
}
}

public ISkill getInner() {
return inner;
}

public void setInner(ISkill inner) {
this.inner = inner;
}

@Override
public WrappedSkillData constructSkillData() {
return new WrappedSkillData(getId(), inner.constructSkillData());
}

@Override
public <T extends SkillData> void loadSkillData(T skillData, SkillTree context, SkillLoadingErrors errors, Config c) {
Config inner = c.getConfig("Parent");
loadSkillData(skillData, context, errors, inner);
}

@Override
public String getId() {
return catalogId;
}

@Override
public void init() {
inner.init();
}

@Override
public void skillLearn(IActiveCharacter character, PlayerSkillContext context) {
inner.skillLearn(character, context);
}

@Override
public void skillUpgrade(IActiveCharacter character, int level, PlayerSkillContext context) {
inner.skillUpgrade(character, level, context);
}

@Override
public void skillRefund(IActiveCharacter character, PlayerSkillContext context) {
inner.skillRefund(character, context);
}

@Override
public SkillSettings getDefaultSkillSettings() {
return inner.getDefaultSkillSettings();
}

@Override
public void onCharacterInit(IActiveCharacter c, int level, PlayerSkillContext context) {
inner.onCharacterInit(c, level, context);
}

@Override
public void onPreUse(IActiveCharacter character, SkillContext skillContext) {
inner.onPreUse(character, skillContext);
}

@Override
public Set<ISkillType> getSkillTypes() {
return inner.getSkillTypes();
}

@Override
public SkillSettings getSettings() {
return inner.getSettings();
}

@Override
public void setSettings(SkillSettings settings) {
inner.setSettings(settings);
}

@Override
public String getDamageType() {
return inner.getDamageType();
}

@Override
public void setDamageType(String type) {
inner.setDamageType(type);
}

@Override
public SkillExecutionType getSkillExecutionType() {
return inner.getSkillExecutionType();
}

public static class WrappedSkillData extends SkillData {

public SkillData wrapped;

public WrappedSkillData(String skill, SkillData wrapped) {
super(skill);
this.wrapped = wrapped;
}

public SkillData getWrapped() {
return wrapped;
}

public void setWrapped(SkillData wrapped) {
this.wrapped = wrapped;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
public class SkillContext {

protected final ArrayList<ActiveSkillPreProcessorWrapper> wrappers = new ArrayList<>();
private PlayerSkillContext esi;
private int cursor;
protected PlayerSkillContext esi;
protected int cursor;
private SkillResult result;
private boolean continueExecution;
protected boolean continueExecution;
private float finalCooldown;
private boolean sorted = false;

public SkillContext(IActiveSkill activeSkill, PlayerSkillContext esi) {
this.esi = esi;
cursor = -1;
resetCursor();
continueExecution = true;
wrappers.add(new ActiveSkillPreProcessorWrapper(PreProcessorTarget.EXECUTION) {
@Override
Expand All @@ -38,14 +39,23 @@ public SkillContext() {

}

public void resetCursor() {
this.cursor = -1;
}

public ISkill getSkill() {
return esi.getSkill();
}

public void sort() {
sorted = true;
wrappers.sort(Comparator.comparing(ActiveSkillPreProcessorWrapper::getTarget));
}

public boolean isSorted() {
return sorted;
}

public void next(IActiveCharacter consumer, PlayerSkillContext info, SkillContext skillResult) {
cursor++;
if (result == SkillResult.CANCELLED || skillResult.continueExecution) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ public void onPreUse(IActiveCharacter character, SkillContext skillContext) {
skillContext.result(SkillResult.CASTER_SILENCED);
return;
}
skillContext.addExecutor(inventoryService.processItemCost(character, info));
skillContext.addExecutor(info.getSkillData().getSkillPreprocessors());
skillContext.sort();

if (!skillContext.isSorted()) {
skillContext.addExecutor(inventoryService.processItemCost(character, info));
skillContext.addExecutor(info.getSkillData().getSkillPreprocessors());
skillContext.sort();
}

skillContext.next(character, info, skillContext);
}

Expand Down
Loading

0 comments on commit c59ceb0

Please sign in to comment.