PC Cafe system.
This commit is contained in:
@@ -99,6 +99,7 @@ import handlers.admincommandhandlers.AdminMessages;
|
||||
import handlers.admincommandhandlers.AdminMobGroup;
|
||||
import handlers.admincommandhandlers.AdminMonsterRace;
|
||||
import handlers.admincommandhandlers.AdminOlympiad;
|
||||
import handlers.admincommandhandlers.AdminPcCafePoints;
|
||||
import handlers.admincommandhandlers.AdminPForge;
|
||||
import handlers.admincommandhandlers.AdminPathNode;
|
||||
import handlers.admincommandhandlers.AdminPcCondOverride;
|
||||
@@ -375,6 +376,7 @@ public class MasterHandler
|
||||
AdminMonsterRace.class,
|
||||
AdminOlympiad.class,
|
||||
AdminPathNode.class,
|
||||
AdminPcCafePoints.class,
|
||||
AdminPetition.class,
|
||||
AdminPForge.class,
|
||||
AdminPledge.class,
|
||||
|
205
trunk/dist/game/data/scripts/handlers/admincommandhandlers/AdminPcCafePoints.java
vendored
Normal file
205
trunk/dist/game/data/scripts/handlers/admincommandhandlers/AdminPcCafePoints.java
vendored
Normal file
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package handlers.admincommandhandlers;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.gameserver.cache.HtmCache;
|
||||
import com.l2jmobius.gameserver.handler.IAdminCommandHandler;
|
||||
import com.l2jmobius.gameserver.model.L2World;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.network.serverpackets.ExPCCafePointInfo;
|
||||
import com.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
|
||||
import com.l2jmobius.gameserver.util.Util;
|
||||
|
||||
/**
|
||||
* Admin PC Points manage admin commands.
|
||||
*/
|
||||
public final class AdminPcCafePoints implements IAdminCommandHandler
|
||||
{
|
||||
private static final String[] ADMIN_COMMANDS =
|
||||
{
|
||||
"admin_pccafepoints",
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean useAdminCommand(String command, L2PcInstance activeChar)
|
||||
{
|
||||
final StringTokenizer st = new StringTokenizer(command, " ");
|
||||
final String actualCommand = st.nextToken();
|
||||
|
||||
if (actualCommand.equals("admin_pccafepoints"))
|
||||
{
|
||||
if (st.hasMoreTokens())
|
||||
{
|
||||
final String action = st.nextToken();
|
||||
|
||||
final L2PcInstance target = getTarget(activeChar);
|
||||
if ((target == null) || !st.hasMoreTokens())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int value = 0;
|
||||
try
|
||||
{
|
||||
value = Integer.parseInt(st.nextToken());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
showMenuHtml(activeChar);
|
||||
activeChar.sendMessage("Invalid Value!");
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case "set":
|
||||
{
|
||||
if (value > Config.PC_CAFE_MAX_POINTS)
|
||||
{
|
||||
showMenuHtml(activeChar);
|
||||
activeChar.sendMessage("You cannot set more than " + Config.PC_CAFE_MAX_POINTS + " PC points!");
|
||||
return false;
|
||||
}
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
target.setPcCafePoints(value);
|
||||
target.sendMessage("Admin set your PC Cafe point(s) to " + value + "!");
|
||||
activeChar.sendMessage("You set " + value + " PC Cafe point(s) to player " + target.getName());
|
||||
target.sendPacket(new ExPCCafePointInfo(value, value, 1));
|
||||
break;
|
||||
}
|
||||
case "increase":
|
||||
{
|
||||
if (target.getPcCafePoints() == Config.PC_CAFE_MAX_POINTS)
|
||||
{
|
||||
showMenuHtml(activeChar);
|
||||
activeChar.sendMessage(target.getName() + " already have max count of PC points!");
|
||||
return false;
|
||||
}
|
||||
|
||||
int pcCafeCount = Math.min(target.getPcCafePoints() + value, Config.PC_CAFE_MAX_POINTS);
|
||||
if (pcCafeCount < 0)
|
||||
{
|
||||
pcCafeCount = Config.PC_CAFE_MAX_POINTS;
|
||||
}
|
||||
target.setPcCafePoints(pcCafeCount);
|
||||
target.sendMessage("Admin increased your PC Cafe point(s) by " + value + "!");
|
||||
activeChar.sendMessage("You increased PC Cafe point(s) of " + target.getName() + " by " + value);
|
||||
target.sendPacket(new ExPCCafePointInfo(pcCafeCount, value, 1));
|
||||
break;
|
||||
}
|
||||
case "decrease":
|
||||
{
|
||||
if (target.getPcCafePoints() == 0)
|
||||
{
|
||||
showMenuHtml(activeChar);
|
||||
activeChar.sendMessage(target.getName() + " already have min count of PC points!");
|
||||
return false;
|
||||
}
|
||||
|
||||
final int pcCafeCount = Math.max(target.getPcCafePoints() - value, 0);
|
||||
target.setPcCafePoints(pcCafeCount);
|
||||
target.sendMessage("Admin decreased your PC Cafe point(s) by " + value + "!");
|
||||
activeChar.sendMessage("You decreased PC Cafe point(s) of " + target.getName() + " by " + value);
|
||||
target.sendPacket(new ExPCCafePointInfo(pcCafeCount, value, 1));
|
||||
break;
|
||||
}
|
||||
case "rewardOnline":
|
||||
{
|
||||
int range = 0;
|
||||
try
|
||||
{
|
||||
range = Integer.parseInt(st.nextToken());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
|
||||
if (range <= 0)
|
||||
{
|
||||
final int count = increaseForAll(L2World.getInstance().getPlayers(), value);
|
||||
activeChar.sendMessage("You increased PC Cafe point(s) of all online players (" + count + ") by " + value + ".");
|
||||
}
|
||||
else if (range > 0)
|
||||
{
|
||||
final int count = increaseForAll(L2World.getInstance().getVisibleObjects(activeChar, L2PcInstance.class, range), value);
|
||||
activeChar.sendMessage("You increased PC Cafe point(s) of all players (" + count + ") in range " + range + " by " + value + ".");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
showMenuHtml(activeChar);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private int increaseForAll(Collection<L2PcInstance> playerList, int value)
|
||||
{
|
||||
int counter = 0;
|
||||
for (L2PcInstance temp : playerList)
|
||||
{
|
||||
if ((temp != null) && (temp.isOnlineInt() == 1))
|
||||
{
|
||||
if (temp.getPcCafePoints() == Integer.MAX_VALUE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int pcCafeCount = Math.min(temp.getPcCafePoints() + value, Integer.MAX_VALUE);
|
||||
if (pcCafeCount < 0)
|
||||
{
|
||||
pcCafeCount = Integer.MAX_VALUE;
|
||||
}
|
||||
temp.setPcCafePoints(pcCafeCount);
|
||||
temp.sendMessage("Admin increased your PC Cafe point(s) by " + value + "!");
|
||||
temp.sendPacket(new ExPCCafePointInfo(pcCafeCount, value, 1));
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
private L2PcInstance getTarget(L2PcInstance activeChar)
|
||||
{
|
||||
return ((activeChar.getTarget() != null) && (activeChar.getTarget().getActingPlayer() != null)) ? activeChar.getTarget().getActingPlayer() : activeChar;
|
||||
}
|
||||
|
||||
private void showMenuHtml(L2PcInstance activeChar)
|
||||
{
|
||||
final NpcHtmlMessage html = new NpcHtmlMessage(0, 1);
|
||||
final L2PcInstance target = getTarget(activeChar);
|
||||
final int points = target.getPcCafePoints();
|
||||
html.setHtml(HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/admin/pccafe.htm"));
|
||||
html.replace("%points%", Util.formatAdena(points));
|
||||
html.replace("%targetName%", target.getName());
|
||||
activeChar.sendPacket(html);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getAdminCommandList()
|
||||
{
|
||||
return ADMIN_COMMANDS;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user