Merge pull request #215 from Jamix77/master

Statistics!!
This commit is contained in:
Daniel Ginovker 2020-03-27 12:09:16 -04:00 committed by GitHub
commit e9164801bb
12 changed files with 308 additions and 0 deletions

View file

@ -86,6 +86,7 @@ public abstract class ClueScrollPlugin extends MapZone implements Plugin<Object>
}
nextStage(player, clue);
if (casket) {
player.getStatisticsManager().getCLUES_COMPLETED().incrementAmount();
player.getInventory().replace(level.getCasket(), clue.getSlot());
} else {
player.getInventory().remove(clue);

View file

@ -154,6 +154,7 @@ public final class GatheringSkillPulse extends SkillPulse<GameObject> {
Projectile.create(player, null, 1776, 35, 30, 20, 25).transform(player, new Location(player.getLocation().getX() + 2, player.getLocation().getY()), true, 25, 25).send();
player.getSkills().addExperience(Skills.WOODCUTTING, resource.getExperience());
player.getSkills().addExperience(Skills.FIREMAKING, resource.getExperience());
player.getStatisticsManager().getLOGS_OBTAINED().incrementAmount();
return false;
}
int reward = resource.getReward();
@ -176,6 +177,7 @@ public final class GatheringSkillPulse extends SkillPulse<GameObject> {
player.getPacketDispatch().sendMessage("You cut a branch from the Dramen tree.");
} else {
player.getPacketDispatch().sendMessage("You get some " + ItemDefinition.forId(reward).getName().toLowerCase() + ".");
player.getStatisticsManager().getLOGS_OBTAINED().incrementAmount();
}
// Calculate if the player should receive a bonus gem or bonus ore or both
if (!isMiningEssence && isMining) {

View file

@ -211,6 +211,10 @@ public abstract class Entity extends Node {
* @param killer The killer of this entity.
*/
public void finalizeDeath(Entity killer) {
if (killer.isPlayer()) {
if (!((Player)killer).isArtificial())
((Player)killer).getStatisticsManager().getENTITIES_KILLED().incrementAmount();
}
skills.restore();
skills.rechargePrayerPoints();
impactHandler.getImpactQueue().clear();

View file

@ -65,6 +65,7 @@ import org.crandor.game.node.entity.player.link.prayer.PrayerType;
import org.crandor.game.node.entity.player.link.quest.QuestRepository;
import org.crandor.game.node.entity.player.link.request.RequestManager;
import org.crandor.game.node.entity.player.link.skillertasks.SkillerTasks;
import org.crandor.game.node.entity.player.link.statistics.PlayerStatisticsManager;
import org.crandor.game.node.item.GroundItem;
import org.crandor.game.node.item.GroundItemManager;
import org.crandor.game.node.item.Item;
@ -99,6 +100,7 @@ import org.crandor.net.packet.out.SkillLevel;
import org.crandor.net.packet.out.UpdateSceneGraph;
import org.crandor.plugin.Plugin;
import org.crandor.tools.StringUtils;
import plugin.activity.pyramidplunder.PlunderObjectManager;
/**
@ -302,6 +304,11 @@ public class Player extends Entity {
* The jobs minigame manager.
*/
private final JobsMinigameManager jobsManager = new JobsMinigameManager(this);
/**
* The statistics manager.
*/
private final PlayerStatisticsManager statisticsManager = new PlayerStatisticsManager(this);
/**
* The logout plugins.
@ -536,6 +543,10 @@ public class Player extends Entity {
return;
}
getPacketDispatch().sendMessage("Oh dear, you are dead!");
if (!isArtificial()) {
getStatisticsManager().getDEATHS().incrementAmount();
}
//If player was a Hardcore Ironman, announce that they died
if (this.getIronmanManager().getMode().equals(IronmanMode.HARDCORE)){ //if this was checkRestriction, ultimate irons would be moved to HARDCORE_DEAD as well
@ -1342,4 +1353,8 @@ public class Player extends Entity {
public JobsMinigameManager getJobsManager() {
return jobsManager;
}
public PlayerStatisticsManager getStatisticsManager() {
return statisticsManager;
}
}

View file

@ -149,6 +149,9 @@ public final class PlayerParser {
case 46:
player.getSkills().parseExpRate(buffer);
break;
case 47:
player.getStatisticsManager().parse(buffer);
break;
default:
System.err.println("[Player parsing] Unhandled opcode: " + opcode + " for " + player.getName() + " - [log=" + Arrays.toString(opcodeLog) + "].");
break;
@ -302,6 +305,8 @@ public final class PlayerParser {
}
player.getSkills().saveExpRate(buffer.put((byte) 46));
player.getStatisticsManager().save(buffer.put((byte)47));
buffer.put((byte) 0); // EOF opcode
buffer.flip();

View file

@ -0,0 +1,115 @@
package org.crandor.game.node.entity.player.link.statistics;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.entity.player.info.login.SavingModule;
/**
* Stuff
* @author jamix77
*
*/
public class PlayerStatisticsManager implements SavingModule {
/**
* Array of statistics.
*/
private final ArrayList<Statistic> STATISTICS = new ArrayList<Statistic>();
private Statistic
AL_KHARID_GATE_PASSES,
FLAX_PICKED,
CLUES_COMPLETED,
ENTITIES_KILLED,
DEATHS,
LOGS_OBTAINED;
/**
* The player instance for this manager.
*/
private final Player player;
public PlayerStatisticsManager(Player player) {
this.player = player;
if (!player.isArtificial())
initStats();
}
private void initStats() {
AL_KHARID_GATE_PASSES = new Statistic(player,this);
FLAX_PICKED = new Statistic(player,this);
CLUES_COMPLETED = new Statistic(player,this);
LOGS_OBTAINED = new Statistic(player,this);
ENTITIES_KILLED = new Statistic(player,this);
DEATHS = new Statistic(player,this);
}
@Override
public void save(ByteBuffer buffer) {
for (int i = 0; i < STATISTICS.size(); i++) {
Statistic s = STATISTICS.get(i);
buffer.put((byte) 1).putInt(i).putInt(s.getStatisticalAmount());
}
buffer.put((byte)0);
}
@Override
public void parse(ByteBuffer buffer) {
int opcode;
while ((opcode = buffer.get() & 0xFF) != 0) {
switch (opcode) {
case 1:
int index = buffer.getInt();
int amount = buffer.getInt();
STATISTICS.get(index).setStatisticalAmount(amount);
break;
}
}
}
/**
* Add a statistic to the arraylist.
* @param statistic
*/
public void addStatistic(Statistic statistic) {
STATISTICS.add(statistic);
}
public ArrayList<Statistic> getSTATISTICS() {
return STATISTICS;
}
public Statistic getAL_KHARID_GATE_PASSES() {
return AL_KHARID_GATE_PASSES;
}
public Statistic getFLAX_PICKED() {
return FLAX_PICKED;
}
public Statistic getCLUES_COMPLETED() {
return CLUES_COMPLETED;
}
public Statistic getLOGS_OBTAINED() {
return LOGS_OBTAINED;
}
public Statistic getENTITIES_KILLED() {
return ENTITIES_KILLED;
}
public Statistic getDEATHS() {
return DEATHS;
}
}

View file

@ -0,0 +1,85 @@
package org.crandor.game.node.entity.player.link.statistics;
import org.crandor.game.node.entity.player.Player;
/**
* A singular statistic.
* @author jamix77
*
*/
public class Statistic {
/**
* The player instance for this manager.
*/
private final Player player;
/**
* The amount of the statistic.
*/
private int statisticalAmount;
/**
*
* Constructs a new @{Code Statistic} object.
* @param player
*/
public Statistic(Player player, PlayerStatisticsManager sm) {
this(player,0,sm);
}
/**
*
* Constructs a new @{Code Statistic} object.
* @param player
* @param amount
*/
public Statistic(Player player,int amount, PlayerStatisticsManager sm) {
this.player = player;
this.statisticalAmount = amount;
sm.addStatistic(this);
}
/**
* Increase only by one.
*/
public void incrementAmount() {
increaseAmount(1);
}
/**
* Decrease only by one.
*/
public void decrementAmount() {
decreaseAmount(1);
}
/**
* Increase by a certain amount.
* @param amount
*/
public void increaseAmount(int amount) {
statisticalAmount += amount;
}
/**
* Decrease by a certain amount.
* @param amount
*/
public void decreaseAmount(int amount) {
statisticalAmount -= amount;
}
/**
* @return the amount
*/
public int getStatisticalAmount() {
return statisticalAmount;
}
public void setStatisticalAmount(int statisticalAmount) {
this.statisticalAmount = statisticalAmount;
}
}

View file

@ -26,6 +26,7 @@ import org.crandor.game.node.entity.player.ai.resource.ResourceAIPManager;
import org.crandor.game.node.entity.player.info.login.PlayerParser;
import org.crandor.game.node.entity.player.link.IronmanMode;
import org.crandor.game.node.entity.player.link.appearance.Gender;
import org.crandor.game.node.entity.player.link.music.MusicEntry;
import org.crandor.game.node.entity.player.link.quest.Quest;
import org.crandor.game.node.entity.player.link.skillertasks.Difficulty;
import org.crandor.game.node.entity.state.EntityState;
@ -100,6 +101,17 @@ public final class DeveloperCommandPlugin extends CommandPlugin {
@Override
public boolean parse(final Player player, String name, String[] args) {
switch (name) {
case "unlockmusic":
for (MusicEntry me : MusicEntry.getSongs().values()) {
player.getMusicPlayer().unlock(me.getId());
}
break;
case "playsong":
player.getMusicPlayer().play(MusicEntry.getSongs().get(Integer.parseInt(args[1])));
player.sendMessage("Playing song: " + MusicEntry.getSongs().get(Integer.parseInt(args[1])).getName());
break;
case "find":
try {
player.getAttributes().put("spawning_items", true);

View file

@ -2,10 +2,14 @@ package plugin.command;
import org.crandor.ServerConstants;
import org.crandor.game.component.Component;
import org.crandor.game.content.skill.Skills;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.entity.player.info.PlayerDetails;
import org.crandor.game.node.entity.player.info.Rights;
import org.crandor.game.node.entity.player.info.login.PlayerParser;
import org.crandor.game.node.entity.player.link.IronmanMode;
import org.crandor.game.node.entity.player.link.RunScript;
import org.crandor.game.node.entity.player.link.music.MusicEntry;
import org.crandor.game.node.entity.player.link.quest.Quest;
import org.crandor.game.node.entity.player.link.quest.QuestRepository;
import org.crandor.game.system.command.CommandPlugin;
@ -53,6 +57,28 @@ public final class PlayerCommandPlugin extends CommandPlugin {
TutorialStage.load(player, stage, false);
break;
*/
case "stats":
player.setAttribute("runscript", new RunScript() {
@Override
public boolean handle() {
try {
Player target = new Player(PlayerDetails.getDetails((String)value));
PlayerParser.parse(target);
if (!target.getDetails().parse()) return true;
sendHiscore(player,target);
}
catch (Exception e) {player.getDialogueInterpreter().sendPlainMessage(false, "That isn't a valid name.");}
return true;
}
});
player.getDialogueInterpreter().sendInput(true, "Enter a username:");
break;
case "shop":
CREDIT_STORE.open(player);
@ -254,6 +280,46 @@ public final class PlayerCommandPlugin extends CommandPlugin {
player.getPacketDispatch().sendString("<col=ecf0f1>::bankresettabs", 275, lineId++);
player.getPacketDispatch().sendString("<col=2c3e50>Reset all of your bank tabs.", 275, lineId++);
}
private void sendHiscore(Player player, Player target) {
if (player.getInterfaceManager().isOpened()) {
player.sendMessage("Finish what you're currently doing.");
return;
}
player.getInterfaceManager().open(new Component(275));
//CLear old data
for (int i = 0; i < 311; i++) {
player.getPacketDispatch().sendString("", 275, i);
}
// Title
player.getPacketDispatch().sendString("<col=ae1515>" + target.getUsername() + "</col>'s stats.", 275, 2);
// Content
int lineId = 11;
player.getPacketDispatch().sendString("Total level: " + target.getSkills().getTotalLevel(), 275, lineId++);
player.getPacketDispatch().sendString("Total xp: " + StringUtils.getFormattedNumber(target.getSkills().getTotalXp()), 275, lineId++);
for (int i = 0; i < Skills.SKILL_NAME.length; i++) {
player.getPacketDispatch().sendString("" + Skills.SKILL_NAME[i] + ": " + target.getSkills().getLevel(i) + " (" + StringUtils.getFormattedNumber((int) Math.round(target.getSkills().getExperience(i))) + ")", 275, lineId++);
}
//stats
player.getPacketDispatch().sendString("<col=ecf0f1>(Since 27/03/2020)</col> Al kharid passes: " + target.getStatisticsManager().getAL_KHARID_GATE_PASSES().getStatisticalAmount(), 275, lineId++);
player.getPacketDispatch().sendString("<col=ecf0f1>(Since 27/03/2020)</col> Logs chopped: " + target.getStatisticsManager().getLOGS_OBTAINED().getStatisticalAmount(), 275, lineId++);
player.getPacketDispatch().sendString("<col=ecf0f1>(Since 27/03/2020)</col> Flax picked: " + target.getStatisticsManager().getFLAX_PICKED().getStatisticalAmount(), 275, lineId++);
player.getPacketDispatch().sendString("<col=ecf0f1>(Since 27/03/2020)</col> Clue scrolls completed: " + target.getStatisticsManager().getCLUES_COMPLETED().getStatisticalAmount(), 275, lineId++);
player.getPacketDispatch().sendString("<col=ecf0f1>(Since 27/03/2020)</col> Enemies killed: " + target.getStatisticsManager().getENTITIES_KILLED().getStatisticalAmount(), 275, lineId++);
player.getPacketDispatch().sendString("<col=ecf0f1>(Since 27/03/2020)</col> Deaths: " + target.getStatisticsManager().getDEATHS().getStatisticalAmount(), 275, lineId++);
player.getPacketDispatch().sendString("Music tracks unlocked: " + target.getMusicPlayer().getUnlocked().size() + "/" + MusicEntry.getSongs().size(), 275, lineId++);
//quests
player.getPacketDispatch().sendString("", 275, lineId++);
player.getPacketDispatch().sendString("<u><col=0000FF>Quests Completed:", 275, lineId++);
for (Quest q : QuestRepository.getQuests().values()) {
player.getPacketDispatch().sendString("" + (q.isCompleted(target) ? "<col=00FF00>" : "<col=ae1515>") + q.getName() + " ", 275, lineId++);
}
}
/**
* Sends information about donating.

View file

@ -103,6 +103,7 @@ public final class BorderGuardDialogue extends DialoguePlugin {
}
if (player.getInventory().remove(COINS)) {
DoorActionHandler.handleAutowalkDoor(player, door);
player.getStatisticsManager().getAL_KHARID_GATE_PASSES().incrementAmount();
} else {
player.getPacketDispatch().sendMessage("You need 10 gold coins to pay the toll.");
}

View file

@ -120,6 +120,7 @@ public final class FieldPickingPlugin extends OptionHandler {
int charge = object.getCharge();
player.getAudioManager().send(2581);
player.getPacketDispatch().sendMessage("You pick some flax.");
player.getStatisticsManager().getFLAX_PICKED().incrementAmount();
if (charge > 1000 + RandomFunction.random(2, 8)) {
object.setActive(false);
object.setCharge(1000);

View file

@ -25,6 +25,7 @@ public class TollGateOptionPlugin extends OptionHandler {
player.getInventory().remove(new Item(995, 10));
player.getPacketDispatch().sendMessage("You quickly pay the 10 gold toll and go through the gates.");
DoorActionHandler.handleAutowalkDoor(player, (GameObject) node);
player.getStatisticsManager().getAL_KHARID_GATE_PASSES().incrementAmount();
return true;
} else {
player.getPacketDispatch().sendMessage("You need 10 gold to pass through the gates.");