Skip to content

Commit

Permalink
Make Discord plugin more extensible/support region
Browse files Browse the repository at this point in the history
- Simplify DiscordState to support more scenarious and use simple
list-based system for determining last event and timeout each event
separately
- Remove actionDelay as that functionality is no longer present
- Add debug log output to DiscordService
- Cleanup DiscordGameEventType to follow new simple DiscordState logic
and add proper priorities to events
- Add support for different type of regions

Signed-off-by: Tomas Slusny <[email protected]>
  • Loading branch information
deathbeam committed Jul 4, 2018
1 parent 68489b2 commit 896f70d
Show file tree
Hide file tree
Showing 5 changed files with 335 additions and 189 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2018, PandahRS <https://github.com/PandahRS>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.discord;

enum DiscordAreaType
{
BOSSES,
CITIES,
DUNGEONS,
MINIGAMES;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,14 @@ public interface DiscordConfig extends Config
@ConfigItem(
keyName = "actionTimeout",
name = "Action timeout (minutes)",
description = "Configures after how long of not updating status will be reset (in minutes)"
description = "Configures after how long of not updating status will be reset (in minutes)",
position = 1
)
default int actionTimeout()
{
return 5;
}

@ConfigItem(
keyName = "actionDelay",
name = "New action delay (seconds)",
description = "Configures the delay before new action will be considered as valid"
)
default int actionDelay()
{
return 10;
}

@ConfigItem(
keyName = "showSkillActivity",
name = "Show activity while skilling",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2018, Tomas Slusny <[email protected]>
* Copyright (c) 2018, PandahRS <https://github.com/PandahRS>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand All @@ -24,103 +25,100 @@
*/
package net.runelite.client.plugins.discord;

import com.google.common.collect.ImmutableSet;
import java.util.Set;
import java.util.function.Function;
import java.util.HashMap;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.runelite.api.Skill;
import static net.runelite.api.Skill.AGILITY;
import static net.runelite.api.Skill.ATTACK;
import static net.runelite.api.Skill.CONSTRUCTION;
import static net.runelite.api.Skill.COOKING;
import static net.runelite.api.Skill.CRAFTING;
import static net.runelite.api.Skill.DEFENCE;
import static net.runelite.api.Skill.FARMING;
import static net.runelite.api.Skill.FIREMAKING;
import static net.runelite.api.Skill.FISHING;
import static net.runelite.api.Skill.FLETCHING;
import static net.runelite.api.Skill.HERBLORE;
import static net.runelite.api.Skill.HITPOINTS;
import static net.runelite.api.Skill.HUNTER;
import static net.runelite.api.Skill.MAGIC;
import static net.runelite.api.Skill.MINING;
import static net.runelite.api.Skill.PRAYER;
import static net.runelite.api.Skill.RANGED;
import static net.runelite.api.Skill.RUNECRAFT;
import static net.runelite.api.Skill.SLAYER;
import static net.runelite.api.Skill.SMITHING;
import static net.runelite.api.Skill.STRENGTH;
import static net.runelite.api.Skill.THIEVING;
import static net.runelite.api.Skill.WOODCUTTING;

@RequiredArgsConstructor

@AllArgsConstructor
@Getter
public enum DiscordGameEventType
enum DiscordGameEventType
{
IN_GAME("In Game", false),
IN_MENU("In Menu", false),
TRAINING_ATTACK(ATTACK, DiscordGameEventType::combatSkillChanged),
TRAINING_DEFENCE(DEFENCE, DiscordGameEventType::combatSkillChanged),
TRAINING_STRENGTH(STRENGTH, DiscordGameEventType::combatSkillChanged),
TRAINING_HITPOINTS(HITPOINTS, DiscordGameEventType::combatSkillChanged),
TRAINING_SLAYER(SLAYER, 1, DiscordGameEventType::combatSkillChanged),
TRAINING_RANGED(RANGED, DiscordGameEventType::combatSkillChanged),
TRAINING_MAGIC(MAGIC, DiscordGameEventType::combatSkillChanged),
TRAINING_PRAYER(PRAYER),
TRAINING_COOKING(COOKING),
TRAINING_WOODCUTTING(WOODCUTTING),
TRAINING_FLETCHING(FLETCHING),
TRAINING_FISHING(FISHING),
TRAINING_FIREMAKING(FIREMAKING),
TRAINING_CRAFTING(CRAFTING),
TRAINING_SMITHING(SMITHING),
TRAINING_MINING(MINING),
TRAINING_HERBLORE(HERBLORE),
TRAINING_AGILITY(AGILITY),
TRAINING_THIEVING(THIEVING),
TRAINING_FARMING(FARMING),
TRAINING_RUNECRAFT(RUNECRAFT),
TRAINING_HUNTER(HUNTER),
TRAINING_CONSTRUCTION(CONSTRUCTION);

private static final Set<Skill> COMBAT_SKILLS = ImmutableSet.of(ATTACK, STRENGTH, DEFENCE, HITPOINTS, SLAYER, RANGED, MAGIC);

private final String state;
private final String imageKey;

IN_GAME("In Game", -3),
IN_MENU("In Menu", -3),
TRAINING_ATTACK(Skill.ATTACK),
TRAINING_DEFENCE(Skill.DEFENCE),
TRAINING_STRENGTH(Skill.STRENGTH),
TRAINING_HITPOINTS(Skill.HITPOINTS, -1),
TRAINING_SLAYER(Skill.SLAYER, 1),
TRAINING_RANGED(Skill.RANGED),
TRAINING_MAGIC(Skill.MAGIC),
TRAINING_PRAYER(Skill.PRAYER),
TRAINING_COOKING(Skill.COOKING),
TRAINING_WOODCUTTING(Skill.WOODCUTTING),
TRAINING_FLETCHING(Skill.FLETCHING),
TRAINING_FISHING(Skill.FISHING),
TRAINING_FIREMAKING(Skill.FIREMAKING),
TRAINING_CRAFTING(Skill.CRAFTING),
TRAINING_SMITHING(Skill.SMITHING),
TRAINING_MINING(Skill.MINING),
TRAINING_HERBLORE(Skill.HERBLORE),
TRAINING_AGILITY(Skill.AGILITY),
TRAINING_THIEVING(Skill.THIEVING),
TRAINING_FARMING(Skill.FARMING),
TRAINING_RUNECRAFT(Skill.RUNECRAFT),
TRAINING_HUNTER(Skill.HUNTER),
TRAINING_CONSTRUCTION(Skill.CONSTRUCTION);

private static final Map<Integer, DiscordGameEventType> FROM_REGION = new HashMap<>();

static
{
for (DiscordGameEventType discordGameEventType : DiscordGameEventType.values())
{
if (discordGameEventType.getRegionIds() == null)
{
continue;
}

for (int region : discordGameEventType.getRegionIds())
{
assert !FROM_REGION.containsKey(region);
FROM_REGION.put(region, discordGameEventType);
}
}
}

private String imageKey;
private String state;
private String details;
private boolean considerDelay = true;
private Function<DiscordGameEventType, Boolean> isChanged = (l) -> true;
private int priority = 0;
private int priority;
private boolean shouldClear;
private boolean shouldTimeout;

DiscordGameEventType(String state, boolean considerDelay)
private DiscordAreaType discordAreaType;
private int[] regionIds;

DiscordGameEventType(Skill skill)
{
this.state = state;
this.imageKey = "default";
this.considerDelay = considerDelay;
this(skill, 0);
}

DiscordGameEventType(Skill skill, int priority, Function<DiscordGameEventType, Boolean> isChanged)
DiscordGameEventType(Skill skill, int priority)
{
this.state = training(skill);
this.priority = priority;
this.imageKey = imageKeyOf(skill);
this.priority = priority;
this.isChanged = isChanged;
this.shouldTimeout = true;
}

DiscordGameEventType(Skill skill, Function<DiscordGameEventType, Boolean> isChanged)
DiscordGameEventType(String areaName, DiscordAreaType areaType, int... regionIds)
{
this.state = training(skill);
this.imageKey = imageKeyOf(skill);
this.isChanged = isChanged;
this.details = exploring(areaType, areaName);
this.priority = -2;
this.discordAreaType = areaType;
this.regionIds = regionIds;
this.shouldClear = true;
}

DiscordGameEventType(Skill skill)
DiscordGameEventType(String state, int priority)
{
this.state = training(skill);
this.imageKey = imageKeyOf(skill);
this.details = state;
this.priority = priority;
this.shouldClear = true;
}

private static String training(final Skill skill)
Expand All @@ -143,17 +141,21 @@ private static String imageKeyOf(final String what)
return "icon_" + what;
}

private static boolean combatSkillChanged(final DiscordGameEventType l)
private static String exploring(DiscordAreaType areaType, String areaName)
{
for (Skill skill : Skill.values())
switch (areaType)
{
if (l.getState().contains(skill.getName()))
{
return !COMBAT_SKILLS.contains(skill);
}
case BOSSES:
return "Fighting: " + areaName;
case DUNGEONS:
return "Exploring: " + areaName;
case CITIES:
return "Location: " + areaName;
case MINIGAMES:
return "Playing: " + areaName;
}

return true;
return "";
}

public static DiscordGameEventType fromSkill(final Skill skill)
Expand Down Expand Up @@ -185,4 +187,9 @@ public static DiscordGameEventType fromSkill(final Skill skill)
default: return null;
}
}

public static DiscordGameEventType fromRegion(final int regionId)
{
return FROM_REGION.get(regionId);
}
}
Loading

0 comments on commit 896f70d

Please sign in to comment.