Ejemplo n.º 1
0
 public Actor() : base()
 {
     //对象的创建要放在构造函数中去
     m_AbilityManager = new AbilityManager();
     //Ability对象也在构造函数中创建
     AddAbility();
     m_actorEventHandler = new ActorEventHandler();
 }
Ejemplo n.º 2
0
        public void SaveChar(ActorPC aChar)
        {
            Load();
            System.IO.FileStream fs = null;
            try
            {
                if (System.IO.Directory.Exists(dbpath + "Save") == false)
                {
                    System.IO.Directory.CreateDirectory(dbpath + "Save");
                }
                if (System.IO.Directory.Exists(dbpath + "Save/" + aChar.userName) == false)
                {
                    System.IO.Directory.CreateDirectory(dbpath + "Save/" + aChar.userName);
                }
                fs = new System.IO.FileStream(dbpath + "Save/" + aChar.userName + "/" + aChar.name + ".dat", System.IO.FileMode.Create);
                //ignore some fields
                ActorEventHandler tmp = aChar.e;
                Dictionary <string, SagaLib.MultiRunTask> tmp2 = aChar.Tasks;
                Actor        tmp3 = aChar.CurTarget;
                Actor        tmp4 = aChar.LastMissionBoard;
                BattleStatus bs   = aChar.BattleStatus;
                aChar.BattleStatus     = null;
                aChar.e                = null;
                aChar.Tasks            = null;
                aChar.CurTarget        = null;
                aChar.LastMissionBoard = null;
                System.Runtime.Serialization.Formatters.Binary.BinaryFormatter xs = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                xs.Serialize(fs, aChar);
                aChar.e                = tmp;
                aChar.Tasks            = tmp2;
                aChar.LastMissionBoard = (ActorItem)tmp4;
                aChar.CurTarget        = tmp3;
                aChar.BattleStatus     = bs;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: can't save char in database");
                throw new Exception(ex.Message + "\r\n" + ex.StackTrace);
            }
            finally
            {
                try
                {
                    if (fs != null)
                    {
                        fs.Close();
                    }
                }

                catch (Exception ex)
                {
                    Console.WriteLine("Error: can't create new char in database");
                    throw new Exception(ex.Message + "\r\n" + ex.StackTrace);
                }
            }
        }
Ejemplo n.º 3
0
        internal void DestroyActor(Actor actor)
        {
            if (Verify.Active(actor))
            {
                log.Info("Destroying {0}", actor);

                //TODO: The call order here might need to be moved around
                // as it can leave the actor in an a weird state for the user
                Peer.ContextPlugin.ActorDespawning(actor);
                Peer.BeforeActorDestroy(actor);

                // Call internal destroy
                actor.InternalDestroy();

                // Remove collider from spatial partition
                if (actor.HasCollider)
                {
                    actor.Collider.RemoveFromPartition();
                }

                // Remove actor connection
                if (actor.Connection != null)
                {
                    actor.Connection.Player.OwnedActors.Remove(actor);
                    actor.Connection = null;
                }

                // Unregister all receivers
                ActorEventHandler.RemoveReceivers(actor.RegisteredEventIds, actor);

                // Remove actor from storage
                actors.Remove(actor.Id);

                // Clear some values
                actor.Id               = 0;
                actor.Name             = "";
                actor.PlayerId         = 0;
                actor.StateStreamRate  = 0;
                actor.SimulationOffset = 0;
            }
        }