I was tired and really didn't care to fine tune it at all but it works and it works quite well.. so enjoy.
For simplicity sake I made a new .cs file named Handlers>CounterKill.cs
Here's the entirety of it.
PHP Code:
using System;
using System.Collections;
using System.Collections.Generic;
using CoEmu_v2_GameServer.Connections;
using CoEmu_v2_GameServer.Entities;
using CoEmu_v2_GameServer.Structs;
using CoEmu_v2_GameServer.Packets;
using System.Threading;
namespace CoEmu_v2_GameServer.Handlers
{
public partial class Handler
{
public class CounterKill
{
public static void CounterKillSwitch(ClientSocket CSocket)//simply toggled it on/off
{
#region counter kill
if (!CSocket.Client.CounterKillOn)//if it's off
{
if (CSocket.Client.CurrentStam >= 100)//and player has 100 stam
{
CSocket.Client.CurrentStam -= 100;//remove the stam
CSocket.Send(ConquerPacket.Status(CSocket, 2, CSocket.Client.CurrentStam, Struct.StatusTypes.Stamina)); //update client stam
CSocket.Client.CounterKillOn = true;//turn on counter kill bool
CSocket.Client.CounterKillTime = 10;//how often it can activate (once every 10 sec)
CSocket.Client.CounterKillRate = 5;// how often it activates (5 percent)
CSocket.Client.LastCounterKill = DateTime.Now;//time when last counter kill activated (now: cannot be used for 10 seconds)
ConquerPacket.ToLocal(ConquerPacket.String(CSocket.Client.ID, 10, "ScapegoatSwitchOpen"), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, 0);//display the counter kill on effect
CSocket.Send(ConquerPacket.Chat(0, "System", CSocket.Client.Name, "CounterKill activated", Struct.ChatType.Top));//print msg to client. never bothered with the little flag effect in top corner
return;
}
else//not enough stam
return;
}
else//counter kill is already on
{
CSocket.Client.CounterKillOn = false;//turn it off
CSocket.Client.LastCounterKill = DateTime.Now;
ConquerPacket.ToLocal(ConquerPacket.String(CSocket.Client.ID, 10, "replacedisappear"), CSocket.Client.X, CSocket.Client.Y, (int)CSocket.Client.Map, 0, 0);//display counter kill off effect
CSocket.Send(ConquerPacket.Chat(0, "System", CSocket.Client.Name, "CounterKill de-activated", Struct.ChatType.Top));//print msg to client, again no lil flag used.
return;
}
#endregion
}
}
}
}
Now you will need some variable in your Entities>Character.cs file.
Code:
public bool CounterKillOn = false;
public DateTime LastCounterKill;
public int CounterKillRate = 0;
Search for
Code:
switch (AType)
Code:
case 37://counter kill
{
Handlers.Handler.CounterKill.CounterKillSwitch(CSocket);
break;
}
You will now need to handle how the actual skill activates. The way I did this was simply by going to any section where a player was attacked (player->player, monster->player, guard->player) and adding these checks...
Here's my code for Monsters attacking players (under monsters.cs in my source)
PHP Code:
if (Attacked.Client.CounterKillOn)
{
if (Calculation.PercentSuccess(Attacked.Client.CounterKillRate))
{
if (DateTime.Now > Attacked.Client.LastCounterKill.AddSeconds(Attacked.Client.CounterKillTime))
{
int DamageReturn = Nano.Rand.Next(Attacked.Client.MinAttack, Attacked.Client.MaxAttack);
Calculation.doMonster(this, ((int)DamageReturn / 2), 2, Attacked);
Handlers.Handler.DoSpell(Attacked.Client.ID, this.ID, this.X, this.Y, Attacked.Client.X, Attacked.Client.Y, this.Map, 6003, DamageReturn, 2);
Attacked.Client.LastCounterKill = DateTime.Now;
goto Jump;
}
}
}
And for simplicity sake, here's mine from Damage.cs (dealing with Player->Players)
PHP Code:
if (Attacked.CounterKillOn)
{
if (Calculation.PercentSuccess(Attacked.CounterKillRate))
{
if (DateTime.Now > Attacked.LastCounterKill.AddSeconds(Attacked.CounterKillTime))
{
int DamageReturn = Nano.Rand.Next(Attacked.MinAttack, Attacked.MaxAttack);
Handlers.Handler.DoSpell(Attacker.ID, Attacker.ID, Attacker.X, Attacker.Y, Attacker.X, Attacker.Y, (int)Attacker.Map, 6003, Damage, 0);
Calculation.doPlayer(Attacker.Owner, Attacker.Owner, (int)DamageReturn / 2, 2);
Attacked.LastCounterKill = DateTime.Now;
Console.WriteLine("Counter Kill Activated: " + Attacked.Name);
return 0;
}
}
}
Anyways: It's all very simple to do but I figured I'd post it cause someone was asking about how to add some reborn skills such as counterkill/reflect so I thought I'd post mine (seeing as Counter Kill for coemu has never been released). There's alot of things that can be improved with this version but it works and that's all that mattered to me at the time.
Also: For fun you can make your gm invincibility command using something like this!
PHP Code:
case "counter":
{
if (Command[1] == "on")
{
if (CSocket.Client.isGM)
{
CSocket.Client.CounterKillOn = true;
CSocket.Client.CounterKillRate = 100;
CSocket.Client.CounterKillTime = 0;
CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Counter kill activated", Struct.ChatType.Top));
ConquerPacket.ToServer(ConquerPacket.Chat(0, "SYSTEM", "ALLUSERS", CSocket.Client.Name + " Has become invincible! All attackers will be punished", Struct.ChatType.Center), 0);
}
}
else
{
CSocket.Client.CounterKillOn = false;
CSocket.Client.CounterKillRate = 0;
CSocket.Client.CounterKillTime = 1000;
CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, " Counter kill deactivated!", Struct.ChatType.Top));
}
break;
}






