Restore a vitality bar each day and on Wednesday restore to full.

Contributed by Sero, CostyKiller.
This commit is contained in:
MobiusDevelopment 2021-06-12 21:42:42 +00:00
parent dcc2fd58f1
commit f6f092f89b
4 changed files with 96 additions and 0 deletions

View File

@ -28,12 +28,17 @@
<event name="#onVitalityReset" />
</schedule>
<!-- Schedule the vitality add one bar task every Day at 6:30 -->
<schedule name="dailyVitalityReset" hour="06" minute="30" dayOfWeek="1,2,4,5,6,7" repeat="true">
<event name="#onDailyVitalityReset" />
</schedule>
<!-- Attach condition to reset if server boots up in after 6:30 and hasn't reset yet -->
<conditionalSchedule>
<run name="reset" if="HASNT_RUN" />
<run name="clanLeaderApply" if="HASNT_RUN" />
<run name="vitalityReset" if="HASNT_RUN" />
<run name="dailyVitalityReset" if="HASNT_RUN" />
</conditionalSchedule>
</scheduler>
</event>

View File

@ -104,6 +104,49 @@ public class DailyTaskManager extends AbstractEventManager<AbstractEvent<?>>
LOGGER.info("Clan leaders has been updated.");
}
@ScheduleTarget
private void onDailyVitalityReset()
{
if (!Config.ENABLE_VITALITY)
{
return;
}
int Vitality = PlayerStat.MAX_VITALITY_POINTS / 4;
for (PlayerInstance player : World.getInstance().getPlayers())
{
final int VP = player.getVitalityPoints();
player.setVitalityPoints(VP + Vitality, false);
for (SubClassHolder subclass : player.getSubClasses().values())
{
final int VPS = subclass.getVitalityPoints();
subclass.setVitalityPoints(VPS + Vitality);
}
}
try (Connection con = DatabaseFactory.getConnection())
{
try (PreparedStatement st = con.prepareStatement("UPDATE character_subclasses SET vitality_points = IF(vitality_points = ?, vitality_points, vitality_points + ?)"))
{
st.setInt(1, PlayerStat.MAX_VITALITY_POINTS);
st.setInt(2, PlayerStat.MAX_VITALITY_POINTS / 4);
st.execute();
}
try (PreparedStatement st = con.prepareStatement("UPDATE characters SET vitality_points = IF(vitality_points = ?, vitality_points, vitality_points + ?)"))
{
st.setInt(1, PlayerStat.MAX_VITALITY_POINTS);
st.setInt(2, PlayerStat.MAX_VITALITY_POINTS / 4);
st.execute();
}
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, "Error while updating vitality", e);
}
LOGGER.info("Daily Vitality Added");
}
@ScheduleTarget
private void onVitalityReset()
{

View File

@ -28,12 +28,17 @@
<event name="#onVitalityReset" />
</schedule>
<!-- Schedule the vitality add one bar task every Day at 6:30 -->
<schedule name="dailyVitalityReset" hour="06" minute="30" dayOfWeek="1,2,4,5,6,7" repeat="true">
<event name="#onDailyVitalityReset" />
</schedule>
<!-- Attach condition to reset if server boots up in after 6:30 and hasn't reset yet -->
<conditionalSchedule>
<run name="reset" if="HASNT_RUN" />
<run name="clanLeaderApply" if="HASNT_RUN" />
<run name="vitalityReset" if="HASNT_RUN" />
<run name="dailyVitalityReset" if="HASNT_RUN" />
</conditionalSchedule>
</scheduler>
</event>

View File

@ -104,6 +104,49 @@ public class DailyTaskManager extends AbstractEventManager<AbstractEvent<?>>
LOGGER.info("Clan leaders has been updated.");
}
@ScheduleTarget
private void onDailyVitalityReset()
{
if (!Config.ENABLE_VITALITY)
{
return;
}
int Vitality = PlayerStat.MAX_VITALITY_POINTS / 4;
for (PlayerInstance player : World.getInstance().getPlayers())
{
final int VP = player.getVitalityPoints();
player.setVitalityPoints(VP + Vitality, false);
for (SubClassHolder subclass : player.getSubClasses().values())
{
final int VPS = subclass.getVitalityPoints();
subclass.setVitalityPoints(VPS + Vitality);
}
}
try (Connection con = DatabaseFactory.getConnection())
{
try (PreparedStatement st = con.prepareStatement("UPDATE character_subclasses SET vitality_points = IF(vitality_points = ?, vitality_points, vitality_points + ?)"))
{
st.setInt(1, PlayerStat.MAX_VITALITY_POINTS);
st.setInt(2, PlayerStat.MAX_VITALITY_POINTS / 4);
st.execute();
}
try (PreparedStatement st = con.prepareStatement("UPDATE characters SET vitality_points = IF(vitality_points = ?, vitality_points, vitality_points + ?)"))
{
st.setInt(1, PlayerStat.MAX_VITALITY_POINTS);
st.setInt(2, PlayerStat.MAX_VITALITY_POINTS / 4);
st.execute();
}
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, "Error while updating vitality", e);
}
LOGGER.info("Daily Vitality Added");
}
@ScheduleTarget
private void onVitalityReset()
{