private bool CheckAndGetLifeZone(Player p, Command cmd) { Life = null; World = null; Name = cmd.Next(); if (String.IsNullOrWhiteSpace(Name)) { p.Message("&WLife name is missing or empty"); return(false); } World = p.World; if (World == null) { p.Message("&WYou are in limbo state. Prepare for eternal torment."); return(false); } lock (World.SyncRoot) { if (World.Map == null) { return(false); } Life = World.GetLife(Name); return(true); } }
public bool TryAddLife(Life2DZone life) { if (null == life) { Logger.Log(LogType.Error, "trying to add null life instance"); return(false); } lock (SyncRoot) { if (null == Map) { return(false); } if (map.LifeZones.ContainsKey(life.Name.ToLower())) { return(false); } map.LifeZones.Add(life.Name.ToLower(), life); if (!_physSchedulers[(int)TaskCategory.Life].Started) { _physSchedulers[(int)TaskCategory.Life].Start(); } } return(true); }
private static void SetAutoReset(Player p, Life2DZone life, string val) { AutoResetMethod method; val = val.ToLower(); switch (val) { case "no": case "none": method = AutoResetMethod.None; break; case "toinitial": case "i": method = AutoResetMethod.ToInitial; break; case "torandom": case "r": case "rnd": method = AutoResetMethod.ToRandom; break; default: p.Message("&WUnrecognized auto reset method " + val + ".\n&h Type '/life help AutoReset' to see all the possible values."); return; } life.AutoReset = method; p.Message("&yAutoReset param set to " + Enum.GetName(typeof(AutoResetMethod), method)); }
private static void SetAutoReset(Player p, Life2DZone life, string val) { AutoResetMethod method = AutoResetMethod.None; val = val.ToLower(); if (val == "no" || val == "none") { method = AutoResetMethod.None; } else if (val == "toinitial" || val == "i") { method = AutoResetMethod.ToInitial; } else if (val == "torandom" || val == "r" || val == "rnd") { method = AutoResetMethod.ToRandom; } else { p.Message("&WUnrecognized auto reset method " + val + ".\n" + "&hType '/life help AutoReset' to see all the possible values."); return; } life.AutoReset = method; p.Message("&yAutoReset param set to " + Enum.GetName(typeof(AutoResetMethod), method)); }
private void LifeCreateCallback(Player player, Vector3I[] marks, object state) { try { lock (_world.SyncRoot) { if (!CheckWorldPermissions(player)) { return; } if (null == _world.Map) { return; } if (null != _world.GetLife(_name)) //check it again, since smone could create it in between { player.Message("&WLife with such name exists already, choose another"); return; } Life2DZone life = new Life2DZone(_name, _world.Map, marks, player, (player.Info.Rank.NextRankUp ?? player.Info.Rank).Name); if (_world.TryAddLife(life)) { player.Message("&yLife was created. Named " + _name); } else { player.Message("&WCoulnd't create life for some reason unknown."); //really unknown: we are under a lock so nobody could create a life with the same name in between } } } catch (Exception e) { player.Message("&WCreate life error: " + e.Message); } }
private static void SetTorus(Player p, Life2DZone life, string val) { if (!bool.TryParse(val, out bool torus)) { p.Message("&WExpected 'true' or 'false' as torus parameter value"); return; } life.Torus = torus; p.Message("&yTorus param set to " + val); }
private static void SetHalfDelay(Player p, Life2DZone life, string val) { if (!int.TryParse(val, out int delay) || delay < 0) { p.Message("&WExpected non-negative integer value as intermediate delay"); return; } life.HalfStepDelay = delay; p.Message("&yIntermediate step delay set to " + val); }
private static void SetDelay(Player p, Life2DZone life, string val) { if (!int.TryParse(val, out int delay) || delay <= 20) { p.Message("&WExpected integer value >=20 as delay"); return; } life.Delay = delay; p.Message("&yStep delay set to " + val); }
private static void SetNewborn(Player p, Life2DZone life, string val) { Block b = Map.GetBlockByName(val); if (b == Block.Undefined) { p.Message("&WUnrecognized block name " + val); return; } life.Newborn = b; p.Message("&yNewborn block set to " + val); }
private static void SetDead(Player p, Life2DZone life, string val) { Block block = Map.GetBlockByName(val); if (block == Block.Undefined) { p.Message("&WUnrecognized block name " + val); return; } life.Dead = block; p.Message("&yDead block set to " + val); }
private static void OnPrint(Player p, Command cmd) { LifeHandler handler = GetCheckedLifeHandler(p, cmd); if (null == handler) { return; } Life2DZone l = handler._life; p.Message("&y" + l.Name + ": " + (l.Stopped ? "stopped" : "started") + ", delay " + l.Delay + ", intermediate delay " + l.HalfStepDelay + ", is" + (l.Torus ? "" : " not") + " on torus, " + "auto reset strategy is " + Enum.GetName(typeof(AutoResetMethod), l.AutoReset) + ", owner is " + l.CreatorName + ", changable by " + l.MinRankToChange + ", block types: " + l.Normal + " is normal, " + l.Empty + " is empty, " + l.Dead + " is dead, " + l.Newborn + " is newborn"); }
public Life2DZone GetLife(string name) { if (string.IsNullOrWhiteSpace(name)) { Logger.Log(LogType.Error, "null or empty string in GetLife"); return(null); } lock (SyncRoot) { if (null == Map) { return(null); } Life2DZone life = null; map.LifeZones.TryGetValue(name.ToLower(), out life); return(life); } }
private static void SetTorus(Player p, Life2DZone life, string val) { bool torus; if (!bool.TryParse(val, out torus)) { p.Message("&WExpected 'true' or 'false' as torus parameter value"); return; } life.Torus = torus; p.Message("&yTorus param set to " + val); }
private bool CheckAndGetLifeZone(Player p, Command cmd) { _life = null; _world = null; _name = cmd.Next(); if (String.IsNullOrWhiteSpace(_name)) { p.Message("&WLife name is missing or empty"); return false; } _world = p.World; if (null == _world) { p.Message("&WYou are in limbo state. Prepare for eternal torment."); return false; } lock (_world.SyncRoot) { if (null == _world.Map) return false; _life = _world.GetLife(_name); return true; } }
private static void SetNormal(Player p, Life2DZone life, string val) { Block b = Map.GetBlockByName(val); if (b==Block.Undefined) { p.Message("&WUnrecognized block name "+val); return; } life.Normal = b; p.Message("&yNormal block set to " + val); }
private static void SetHalfDelay(Player p, Life2DZone life, string val) { int delay; if (!int.TryParse(val, out delay) || delay < 0) { p.Message("&WExpected non-negative integer value as intermediate delay"); return; } life.HalfStepDelay = delay; p.Message("&yIntermediate step delay set to " + val); }
private static void SetDelay(Player p, Life2DZone life, string val) { int delay; if (!int.TryParse(val, out delay) || delay <=20) { p.Message("&WExpected integer value >=20 as delay"); return; } life.Delay = delay; p.Message("&yStep delay set to "+val); }
private static void SetAutoReset(Player p, Life2DZone life, string val) { AutoResetMethod method; val = val.ToLower(); if (val == "no" || val == "none") method = AutoResetMethod.None; else if (val == "toinitial" || val == "i") method = AutoResetMethod.ToInitial; else if (val=="torandom" || val=="r" || val=="rnd") method = AutoResetMethod.ToRandom; else { p.Message("&WUnrecognized auto reset method "+val+".\n&h Type '/life help AutoReset' to see all the possible values."); return; } life.AutoReset = method; p.Message("&yAutoReset param set to " + Enum.GetName(typeof(AutoResetMethod), method)); }
private void LifeCreateCallback(Player player, Vector3I[] marks, object state) { try { lock (_world.SyncRoot) { if (!CheckWorldPermissions(player)) return; if (null == _world.Map) return; if (null != _world.GetLife(_name)) //check it again, since smone could create it in between { player.Message("&WLife with such name exists already, choose another"); return; } Life2DZone life = new Life2DZone(_name, _world, marks, player.Name, (player.Info.Rank.NextRankUp??player.Info.Rank).Name); if (_world.TryAddLife(life)) player.Message("&yLife was created. Named " + _name); else player.Message("&WCoulnd't create life for some reason unknown."); //really unknown: we are under a lock so nobody could create a life with the same name in between } } catch (Exception e) { player.Message("&WCreate life error: " + e.Message); } }
public bool TryAddLife(Life2DZone life) { if (null==life) { Logger.Log(LogType.Error, "trying to add null life instance"); return false; } lock (SyncRoot) { if (null==Map) return false; if (map.LifeZones.ContainsKey(life.Name.ToLower())) return false; map.LifeZones.Add(life.Name.ToLower(), life); if (!_physSchedulers[(int)TaskCategory.Life].Started) _physSchedulers[(int)TaskCategory.Life].Start(); } return true; }
private static void SetAutoReset( Player p, Life2DZone life, string val ) { AutoResetMethod method; val = val.ToLower(); switch (val) { case "none": case "no": method = AutoResetMethod.None; break; case "i": case "toinitial": method = AutoResetMethod.ToInitial; break; case "rnd": case "r": case "torandom": method = AutoResetMethod.ToRandom; break; default: p.Message( "&WUnrecognized auto reset method " + val + ".\n&h Type '/life help AutoReset' to see all the possible values." ); return; } life.AutoReset = method; p.Message( "&yAutoReset param set to " + Enum.GetName( typeof( AutoResetMethod ), method ) ); }