示例#1
0
 private void WO_NPC_OnDestroy()
 {
     if (_dialog != null)
     {
         _dialog.NPC[_npc.DialogIndex] = null;
         if (_owner != null)
         {
             _server.Dialogs.RemoveClone(_dialog.ID, _owner);
         }
     }
     if (_owner != null)
     {
         _owner.Clones.Remove(_npc.ID);
     }
     if (_original != null && !_original.IsDead)
     {
         _original._view.RebuildVisibility();
     }
     m_char    = null;
     _wears    = null;
     _owner    = null;
     _dialog   = null;
     _original = null;
     shop_ser  = default(SER_Shop);
     wears_ser = default(SER_Wears);
 }
示例#2
0
 public WO_NPC(DB_WorldObject data, ObjectsMgr manager)
     : base(manager.GetNewGuid() | Constants.ReleaseGuide, manager)
 {
     _data = data;
     if (!DataMgr.Select(data.ObjectID, out _npc))
     {
         ServerLogger.LogError($"NPC id {data.ObjectID} doesn't exist");
     }
     if ((_npc.Flags & NPCFlags.Dialog) > 0)
     {
         _dialog = _server.Dialogs.GetDialog(_npc.Dialog);
     }
     if ((_npc.Flags & NPCFlags.Trader) > 0)
     {
         shop_ser = new SER_Shop(_npc.Items, $"{_npc.Pony.Name}'s shop");
     }
     if ((_npc.Flags & NPCFlags.Wears) > 0)
     {
         DB_Item entry; byte slot;
         _wears    = new Dictionary <int, InventoryItem>();
         wears_ser = new SER_Wears(_wears);
         foreach (var item in _npc.Wears)
         {
             if (item > 0 && DataMgr.Select(item, out entry))
             {
                 slot = entry.Slot.ToWearableIndex();
                 if (_wears.ContainsKey(slot))
                 {
                     ServerLogger.LogWarn($"NPC id {data.ObjectID} duplicate wear slot {entry.Slot}");
                 }
                 else
                 {
                     _wears[slot] = new InventoryItem(item);
                 }
             }
         }
     }
     OnSpawn   += WO_NPC_OnSpawn;
     OnDespawn += WO_NPC_OnDespawn;
     OnDestroy += WO_NPC_OnDestroy;
     if ((_npc.Flags & NPCFlags.ScriptedMovement) > 0)
     {
         AddComponent(new ScriptedMovement(_npc.Movement, this));
     }
     else
     {
         AddComponent(new NullMovement(this));
     }
     m_char = new Character(_npc.ID, -1, _npc.Level, -1, _npc.Pony, null);
     Spawn();
 }
示例#3
0
 public WO_NPC(WO_NPC original, MapPlayer owner)
     : base(original._manager.GetNewGuid() | Constants.CRObject, original._manager)
 {
     _owner    = owner;
     _original = original;
     _npc      = original._npc;
     _data     = original._data;
     if ((_npc.Flags & NPCFlags.Dialog) > 0)
     {
         _dialog = _server.Dialogs.GetClone(_npc.Dialog, owner);
     }
     if ((_npc.Flags & NPCFlags.Trader) > 0)
     {
         shop_ser = new SER_Shop(_npc.Items, $"{_npc.Pony.Name}'s shop");
     }
     if ((_npc.Flags & NPCFlags.Wears) > 0)
     {
         DB_Item entry; byte slot;
         _wears    = new Dictionary <int, InventoryItem>();
         wears_ser = new SER_Wears(_wears);
         foreach (var item in _npc.Wears)
         {
             if (item > 0 && DataMgr.Select(item, out entry))
             {
                 slot = entry.Slot.ToWearableIndex();
                 if (_wears.ContainsKey(slot))
                 {
                     ServerLogger.LogWarn($"NPC id {_data.ObjectID} duplicate wear slot {entry.Slot}");
                 }
                 else
                 {
                     _wears[slot] = new InventoryItem(item);
                 }
             }
         }
     }
     OnSpawn   += WO_NPC_OnSpawn;
     OnDespawn += WO_NPC_OnDespawn;
     OnDestroy += WO_NPC_OnDestroy;
     if ((_npc.Flags & NPCFlags.ScriptedMovement) > 0)
     {
         AddComponent(new ScriptedMovement(original._movement as ScriptedMovement, this));
     }
     else
     {
         AddComponent(new NullMovement(this));
     }
     m_char = new Character(_npc.ID, -1, _npc.Level, -1, _npc.Pony, null);
     Spawn();
 }