-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
374 additions
and
41 deletions.
There are no files selected for viewing
140 changes: 140 additions & 0 deletions
140
API/src/main/java/cz/neumimto/rpg/api/skills/RepeatingSkill.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
API/src/main/java/cz/neumimto/rpg/api/skills/WrappedSkill.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.