Esempio n. 1
0
        public static Type GetTypeByName(string name)
        {
            int typeId = -1;

            try {
                typeId = CustomEntityManager.GetIdByTypeName(name);
                return(CustomEntityManager.GetTypeById(typeId));
            } catch (HamstarException e) {
                //throw new HamstarException( "!ModHelpers.CustomEntityManager.GetTypeByName - No CustomEntity " + name, e );
                throw new HamstarException("No CustomEntity " + name, e);
            }
        }
Esempio n. 2
0
        ////////////////

        public override string ToString()
        {
            string basename = "";
            string typeid   = "type " + CustomEntityManager.GetIdByTypeName(this.GetType().Name);
            string who      = "";
            string owner    = ", owner:";

            if (this.Core == null)
            {
                basename = "Undefined entity";
            }
            else
            {
                basename = this.Core.DisplayName;
                who      = ", who " + this.Core.whoAmI;
            }

            if (!string.IsNullOrEmpty(this.OwnerPlayerUID))
            {
                owner += " " + this.OwnerPlayerUID.Substring(0, 8) + "...";
            }
            if (this.OwnerPlayerWho != -1)
            {
                owner += " " + (("'" + Main.player[this.OwnerPlayerWho]?.name + "'") ?? "MISSING_PLAYER") + "':" + this.OwnerPlayerWho;
            }
            if (this.OwnerPlayerUID == "" && this.OwnerPlayerWho == -1)
            {
                owner += " none";
            }

            if (this.Components != null)
            {
                typeid = typeid + ":" + this.Components.Count();
            }

            return(basename + " [" + this.GetType().Name + "] (" + typeid + who + owner + ")");
        }
Esempio n. 3
0
        protected override void WriteStream(BinaryWriter writer)
        {
            if (!this.IsInitialized)
            {
                //throw new HamstarException( "!ModHelpers.SerializableCustomEntity.WriteStream - Not initialized." );
                throw new HamstarException("Not initialized.");
            }

            if (Main.netMode != 1)
            {
                this.RefreshOwnerWho();
            }

            CustomEntityCore core     = this.Core;
            byte             ownerWho = this.OwnerPlayerWho == -1 ? (byte)255 : (byte)this.OwnerPlayerWho;

            writer.Write((ushort)CustomEntityManager.GetIdByTypeName(this.MyTypeName));
            writer.Write((byte)ownerWho);
//LogHelpers.Log( "WRITE id: "+this.ID+", name: "+core.DisplayName+", templates: "+ CustomEntityTemplates.TotalEntityTemplates());
//LogHelpers.Log( "WRITE2 who: "+core.whoAmI+", component count: "+this.Components.Count );
            writer.Write((ushort)core.whoAmI);
            writer.Write((string)core.DisplayName);
            writer.Write((float)core.position.X);
            writer.Write((float)core.position.Y);
            writer.Write((short)core.direction);
            writer.Write((ushort)core.width);
            writer.Write((ushort)core.height);
            writer.Write((float)core.velocity.X);
            writer.Write((float)core.velocity.Y);

            for (int i = 0; i < this.Components.Count; i++)
            {
                this.Components[i].WriteStreamForwarded(writer);
            }
//LogHelpers.Log( "WRITE "+this.ToString()+" pos:"+ core.position );
        }