Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
 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);
     }
 }
Esempio n. 5
0
            public void UpdateLife2DZone(Life2DZone life)
            {
                //the life is not running, no locks needed
                life._bounds = Bounds;
                //we only will be needed one assignment depending on the orientation (see the public life constructor)
                //but it doesnt hurt to assign all variables, which is shorter than a switch statement
                life._coords.X    = Bounds.XMin;
                life._coords.Y    = Bounds.YMin;
                life._coords.Z    = Bounds.ZMin;
                life._orientation = Orient;

                life._normal  = Normal;
                life._empty   = Empty;
                life._dead    = Dead;
                life._newborn = Newborn;

                life._state         = RuntimeState;
                life._halfStepDelay = HalfStepDelay;
                life._delay         = Delay;
                life._autoReset     = AutoReset;

                life.CreatorName     = CreatorName;
                life.MinRankToChange = MinRankToChange;

                life._life2d = new Life2d(Dim0, Dim1);
                life._life2d.SetState(To2DArray(CurrentState, Dim0, Dim1));
                life._initialState = To2DArray(InitialState, Dim0, Dim1);
            }
Esempio n. 6
0
 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);
 }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        public static Life2DZone Deserialize(string name, string sdata, Map map)
        {
            Life2DZone life = new Life2DZone(name, map);

            byte[] bdata = Convert.FromBase64String(sdata);
            DataContractSerializer serializer = new DataContractSerializer(typeof(SerializedData));
            MemoryStream           s          = new MemoryStream(bdata);
            SerializedData         data       = ( SerializedData )serializer.ReadObject(s);

            data.UpdateLife2DZone(life);
            return(life);
        }
Esempio n. 12
0
 public void Deserialize(string group, string key, string value, Map map)
 {
     try {
         Life2DZone life = Life2DZone.Deserialize(key, value, map);
         if (map.LifeZones.ContainsKey(key.ToLower()))
         {
             Logger.Log(LogType.Error, "Map loading warning: duplicate life name found: " + key + ", ignored");
             return;
         }
         map.LifeZones.Add(key.ToLower(), life);
     } catch (Exception ex) {
         Logger.Log(LogType.Error, "LifeSerialization.Deserialize: Error deserializing life {0}: {1}", key, ex);
     }
 }
Esempio n. 13
0
		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;
			}
		}
Esempio n. 14
0
        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");
        }
Esempio n. 15
0
            public SerializedData(Life2DZone life)
            {
                lock (life._life2d) {
                    Bounds = life._bounds;
                    Orient = life._orientation;

                    Normal  = life._normal;
                    Empty   = life._empty;
                    Dead    = life._dead;
                    Newborn = life._newborn;

                    RuntimeState  = life._state;
                    HalfStepDelay = life._halfStepDelay;
                    Delay         = life._delay;
                    AutoReset     = life._autoReset;

                    CreatorName     = life.CreatorName;
                    MinRankToChange = life.MinRankToChange;

                    CurrentState = To1DArray(life._life2d.GetArrayCopy(), out Dim0, out Dim1);
                    InitialState = To1DArray((byte[, ])life._initialState.Clone(), out Dim0, out Dim1);
                }
            }
Esempio n. 16
0
 public Task(World w, Life2DZone life)
     : base(w)
 {
     _life = life;
 }