Пример #1
0
        public void OnLoad()
        {
            var partLoader = new PartLoader(init);

            foreach (var part in partManager.GetPartsOrDefault <ISaveLoadable>())
            {
                part.OnLoad(partLoader);
            }

            var effectData = init.Nodes.Where(n => n.Key == nameof(ActorEffect));

            foreach (var effect in effectData)
            {
                effects.Add(new ActorEffect(this, effect.Children));
            }

            init = null;
        }
Пример #2
0
 public PartLoader(ActorInit init)
 {
     nodes = init.Nodes;
 }
Пример #3
0
 public Actor(World world, ActorInit init, uint overrideID) : this(world, init)
 {
     ID = overrideID;
 }
Пример #4
0
        public Actor(World world, ActorInit init) : base(init.Position, null)
        {
            World = world;

            Type     = init.Type;
            Team     = init.Team;
            IsPlayer = init.IsPlayer;
            IsBot    = init.IsBot;

            Height = init.Height;

            ID        = init.ID;
            this.init = init;

            CurrentTerrain = world.TerrainAt(TerrainPosition);

            // Parts
            partManager = new PartManager();
            foreach (var partinfo in init.Type.PartInfos)
            {
                if (partinfo is BotPartInfo && !IsBot)
                {
                    continue;
                }

                var part = partinfo.Create(this);
                partManager.Add(part);

                // Cache some important parts
                if (part is MobilePart mobile)
                {
                    Mobile = mobile;
                }
                if (part is MotorPart motor)
                {
                    Motor = motor;
                }
                else if (part is HealthPart health)
                {
                    Health = health;
                }
                else if (part is RevealsShroudPart revealsShroud)
                {
                    RevealsShroud = revealsShroud;
                }
                else if (part is WeaponPart weapon)
                {
                    Weapon = weapon;
                }
                else if (part is WorldPart worldPart)
                {
                    WorldPart = worldPart;
                }
                else if (part is BotPart botPart)
                {
                    Bot = botPart;
                }
                else if (part is PlayerSwitchPart)
                {
                    IsPlayerSwitch = true;
                }
            }

            if (IsBot && Bot == null)
            {
                IsBot = false;                 // BotPart is not there, thus there's no bot
            }
            if (IsPlayer)
            {
                partManager.Add(new PlayerPart(this));
            }

            tickParts         = partManager.GetPartsOrDefault <ITick>();
            editorTickParts   = partManager.GetPartsOrDefault <ITickInEditor>();
            renderParts       = partManager.GetPartsOrDefault <IRenderable>();
            accelerationParts = partManager.GetPartsOrDefault <INoticeAcceleration>();
            moveParts         = partManager.GetPartsOrDefault <INoticeMove>();
            stopParts         = partManager.GetPartsOrDefault <INoticeStop>();

            Physics = Type.Physics == null ? SimplePhysics.Empty : new SimplePhysics(this, Type.Physics.Type);

            if (Health != null && init.Health >= 0f)
            {
                Health.RelativeHP = init.Health;
            }

            var hoverPart = GetPartOrDefault <HoverPart>();

            if (hoverPart != null)
            {
                Height = hoverPart.DefaultHeight;
            }
        }
Пример #5
0
 public static Actor Create(World world, ActorInit init, bool overrideID)
 {
     return(overrideID ? new Actor(world, init, world.Game.NextActorID) : new Actor(world, init));
 }