fCraft.World.TryAddLife C# (CSharp) Method

TryAddLife() public method

public TryAddLife ( Life2DZone life ) : bool
life Life2DZone
return bool
        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;
        }

Usage Example

Example #1
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);
     }
 }