namespace add_m3rfa.game
{
public class nobiltypolewar
{
public const int serf = 0,
// knight = 1,
// baron = 3,
earl = 5,
duke = 7,
prince = 9,
king = 12;
public static sobnpcspawn[] poles = new sobnpcspawn[13];
public static uint[] poleswinners = new uint[13];
public static safedictionary<uint, entity>[] allscores = new safedictionary<uint, entity>[13];
public static datetime warstart;
public static map map;
public static bool iswar = false;
public static bool allpole = false;
private idisposable subscriber;
public nobiltypolewar()
{
map = kernel.maps[1015].makedynamicmap();
subscriber = world.subscribe(work, 1000);
}
public void work(int time)
{
if (iswar)
if (datetime.now > warstart.addminutes(59))
endwar();
if (copra_times.start.nobiltywarpole && !iswar)
startwar();
if (iswar)
{
if (time32.now > scoresendstamp.addseconds(3))
{
scoresendstamp = time32.now;
sendscores();
}
}
if (iswar)
if (datetime.now > warstart.addminutes(59))
{
allpole = true;
foreach (var item in program.values)
{
if (item.map.id == map.id)
{
for (int i = 0; i < poleswinners.length; i++)
{
var winner = poleswinners[i];
if (item.player.uid != winner)
item.player.teleport(1002, 300, 278);
}
}
}
}
}
public static void join(client.gamestate client)
{
if (iswar)
{
var cooord = map.randomcoordinates();
client.player.teleport(map.id, 737, 576);
client.ondisconnect = p =>
{
p.player.teleport(1002, 300, 278);
client.player.pkmode = game.enums.pkmode.pk;
client.send(new data(true) { uid = client.player.uid, id = data.changepkmode, dwparam = (uint)client.player.pkmode });
};
//client.player.ondeath = p =>
//{
// if (p.mapid == map.id)
// {
// var cooordx = map.randomcoordinates();
// p.teleport(map.id, cooordx.item1, cooordx.item2);
// p.bringtolife();
// }
//};
}
}
public static void startwar()
{
try
{
if (iswar)
endwar();
allpole = false;
iswar = true;
warstart = datetime.now;
if (!constants.pkfreemaps.contains(map.id))
constants.pkfreemaps.add(map.id);
poles = new sobnpcspawn[13];
poleswinners = new uint[13];
map.statues.clear();
map.npcs.clear();
start();
summon("king", 730, 584, king);
summon("prince", 730, 563, prince);
summon("duke", 717, 563, duke);
summon("earl", 716, 584, earl);
summon("all", 724, 573, serf);
kernel.sendworldmessage(new message(" nobiltypolewar war began ", color.white, message.center), program.values);
foreach (var client in program.values)
client.messagebox("nobiltypolewar start would you like to join and won claimed the claimed the prize " + serverrates.nobiltypolewar + " cps ?",
p => { p.player.teleport(1002, 342, 272); }, null, 60);
}
catch (exception ex)
{
console.writeline(ex);
program.saveexception(ex);
}
}
public static bool attack(uint addscore, entity entity, sobnpcspawn pole)
{
if (!iswar)
return false;
int _class = (int)entity.nobilityrank;
if (_class >= 13) return false;
var pole = poles[_class];
if (pole != null)
{
if (!allpole)
{
if (pole != pole)
return false;
}
else
{
if (poles[serf] != pole)
return false;
for (int i = 0; i < poleswinners.length; i++)
{
var winner = poleswinners[i];
if (entity.uid != winner)
entity.teleport(1002, 300, 278);
}
}
if (poleswinners[_class] == entity.uid)
return false;
if (addscore > 0)
addscore(addscore, entity, pole);
return true;
}
return false;
}
public static void summon(string name, ushort x, ushort y, int rank)
{
sobnpcspawn base = new sobnpcspawn();
base.uid = map.entityuidcounter2.next;
base.mesh = 8686;
base.type = enums.npctype.stake;
base.sort = 21;
base.showname = true;
base.name = name;
base.hitpoints = base.maxhitpoints = 2000000;
base.mapid = map.id;
base.x = x;
base.y = y;
poles[rank] = base;
if (!map.npcs.containskey(base.uid))
map.npcs.add(base.uid, base);
}
#region score
public static bool firstround = false;
public static time32 scoresendstamp, lastwin;
public static void start()
{
allscores = new safedictionary<uint, entity>[13];
warstart = datetime.now;
firstround = true;
foreach (var c in program.values)
c.player.warscore = 0;
iswar = true;
}
public static void reset(int _class)
{
foreach (var c in program.values.where(p => p.player.nobilityrank == (nobilityrank)_class))
c.player.warscore = 0;
iswar = true;
}
public static void finishround(sobnpcspawn pole, int _class)
{
entity polekeeper;
lastwin = time32.now;
firstround = false;
sortscores(out polekeeper, _class);
if (polekeeper != null)
{
kernel.sendworldmessage(new message("" + polekeeper.name + " has won this round [nobiltypolewar]!", system.drawing.color.red, message.center), program.values);
pole.name = polekeeper.name;
poleswinners[_class] = polekeeper.uid;
}
pole.hitpoints = pole.maxhitpoints;
foreach (var c in program.values)
{
if (c.map.id == map.id)
pole.sendspawn(c);
}
reset(_class);
}
public static void addscore(uint addscore, entity entity, sobnpcspawn pole)
{
if (entity != null)
{
if (pole.hitpoints <= addscore)
pole.hitpoints = 0;
var scores = allscores[(ushort)((int)entity.nobilityrank)];
if (scores == null)
scores = allscores[(ushort)((int)entity.nobilityrank)] = new safedictionary<uint, entity>();
if (!scores.containskey(entity.uid))
scores.add(entity.uid, entity);
entity.warscore += addscore;
if ((int)pole.hitpoints <= 0)
{
finishround(pole, (int)entity.nobilityrank);
return;
}
}
}
public static void sendscores()
{
if (allpole)
{
entity currenttopleader;
var scoremessages= sortscores(out currenttopleader, 0);
for (int c = 0; c < scoremessages.length; c++)
{
message msg = new message(scoremessages[c], system.drawing.color.red, c == 0 ? Message.firstrightcorner : Message.continuerightcorner);
kernel.sendworldmessage(msg, program.values, map.id);
}
return;
}
for (int i = 0; i < allscores.length; i++)
{
var scores = allscores[i];
if (scores == null)
continue;
if (scores.count == 0)
continue;
entity currenttopleader;
var scoremessages = sortscores(out currenttopleader, i);
if (scoremessages == null)
continue;
for (int c = 0; c < scoremessages.length; c++)
{
message msg = new message(scoremessages[c], system.drawing.color.red, c == 0 ? Message.firstrightcorner : Message.continuerightcorner);
foreach (client.gamestate client in program.values)
{
if (client != null)
{
if (client.map.id == map.id)
{
if (client.player.nobilityrank == (nobilityrank)i)
client.send(msg);
}
}
}
}
}
}
private static string[] sortscores(out entity winner, int i)
{
winner = null;
list<string> ret = new list<string>();
int place = 0;
var scores = allscores[i];
if (scores == null) return new string[0];
foreach (var e in scores.values.orderbydescending((p) => p.warscore))
{
if (place == 0)
winner = e;
string str = "no " + (place + 1).tostring() + ": " + e.name + "(" + e.warscore + ")";
ret.add(str);
place++;
if (place == 4)
break;
}
return ret.toarray();
}
#endregion
public static void endwar()
{
kernel.sendworldmessage(new message(" nobiltypole war has ended ", system.drawing.color.red, message.center), program.values);
iswar = false;
map.npcs.clear();
foreach (var client in program.values)
if (client.player.mapid == map.id)
client.player.teleport(1002, 309, 192);
}
public static void getreward(gamestate c, uint cps)
{
for (int i = 0; i < poleswinners.length; i++)
{
var winner = poleswinners[i];
if (c.player.uid == winner)
{
uint cpss = 0;
if (i == 0)
cpss = cps;
else
cpss += cps / 2;
c.player.conquerpoints += serverrates.nobiltypolewar;
c.player.onlinepoints += 30;
// c.player.boundcps += serverrates.bigbtops;
c.player.addtopstatus(update.flags3.conuqersuperye llow, 3, datetime.now.addhours(23));
// c.player.addtopstatus(update.flags3.goldbricksuper , 3, datetime.now.addhours(23));
poleswinners[i] = 0;
add_m3rfa.kernel.sendworldmessage(new message("congratulations " + c.player.name + " the winner nobiltypolewar prize [" + serverrates.nobiltypolewar + "] conquerpoints & [" + serverrates.bigbtops + "] cpsbound & [30] onlinepoints ", system.drawing.color.white, message.center), program.values);
//program.addwarlog("nobiltypolewar", cps.tostring(), c.player.name);
}
}
}
internal static void end()
{
throw new notimplementedexception();
}
}
}
///////////////////////////////////
وده المفرود انو معاد الحرب بس ازي مش موجود في الوراد ولو عاوز اضيف في الورد اضيف اي ؟
+ الحرب مش شغاله عاوز اعدل علي المعاد اخليه كل ساعه مثل
/////////////////////////////////////////
public void work(int time)
{
if (iswar)
if (datetime.now > warstart.addminutes(59))
endwar();
if (copra_times.start.nobiltywarpole && !iswar)
startwar();
if (iswar)
{
if (time32.now > scoresendstamp.addseconds(3))
{
scoresendstamp = time32.now;
sendscores();
}
}
if (iswar)
if (datetime.now > warstart.addminutes(59))
{
allpole = true;
foreach (var item in program.values)
{
if (item.map.id == map.id)
{
for (int i = 0; i < poleswinners.length; i++)
{
var winner = poleswinners[i];
if (item.player.uid != winner)
item.player.teleport(1002, 300, 278);
}
}
}
}
}
//////////////////////////
ممكن تقلولي يا شباب ايه المشكله ؟ ضفت الكلاس وضفت الحرب ؟ ايه المشكله الحرب مشتغلت ليه ولهاش اضافة في الورد ؟ ولو عاوز اغير معدها ؟