Esempio n. 1
0
    public void SpawnItem(string itemPrototypeName, Vector2 position)
    {
        EntityPrototype prototype = GetProtoType(itemPrototypeName);

        if (prototype == null)
        {
            Debug.LogError("Could no find item prototype named " + itemPrototypeName);
            return;
        }
        GameObject entityGO = pool.GetObjectForType("Entity", true, position);

        if (entityGO == null)
        {
            // Make a new one?
            return;
        }
        Entity item = new Entity(itemPrototypeName, prototype.entityType, ReadProtoComponents(prototype.components));

        ItemComponent itemC = (ItemComponent)item.GetEntityComponent(ComponentID.Item);

        itemC.positionData = new MoveData(position.x, position.y);
        item.InitComponent(entityGO);
        EntityGOMap.Add(item, entityGO);
        Items.Add(item);
    }
Esempio n. 2
0
    public SaveMachine(EntityPrototype proto) : base(proto)
    {
        mEntityType = EntityType.Object;


        Body.mIsKinematic = false;
    }
Esempio n. 3
0
    public NavSystem(EntityPrototype proto) : base(proto)
    {
        mEntityType = EntityType.Object;


        Body.mIsKinematic = false;
    }
    public MedicalBay(EntityPrototype proto) : base(proto)
    {
        mEntityType = EntityType.Object;


        Body.mIsKinematic = false;
    }
Esempio n. 5
0
        private void NewButtonClicked(EntitySpawnSelectButton sender, EntityPrototype template, string templateName)
        {
            if (sender.Selected)
            {
                sender.Selected = false;
                _placementManager.Clear();
                return;
            }

            foreach (
                var curr in
                _entityList.Components.Where(curr => curr.GetType() == typeof(EntitySpawnSelectButton)))
            {
                ((EntitySpawnSelectButton)curr).Selected = false;
            }

            var overrideMode = "PlaceFree";

            if (_lstOverride.CurrentlySelected != null)
            {
                overrideMode = _lstOverride.CurrentlySelected.Text;
            }

            var newObjInfo = new PlacementInformation
            {
                PlacementOption = overrideMode.Length > 0 ? overrideMode : template.PlacementMode,
                EntityType      = templateName,
                Range           = 2,
                IsTile          = false
            };

            _placementManager.BeginPlacing(newObjInfo);

            sender.Selected = true; //This needs to be last.
        }
        public EntitySpawnSelectButton(EntityPrototype entityTemplate, string templateName)
        {
            var spriteNameParam = entityTemplate.GetBaseSpriteParameters().FirstOrDefault();
            var spriteName      = "";

            if (spriteNameParam != null)
            {
                spriteName = spriteNameParam.GetValue <string>();
            }
            var objectName = entityTemplate.Name;

            _associatedTemplate     = entityTemplate;
            _associatedTemplateName = templateName;

            _sprite = new Sprite(_resourceCache.GetSprite(spriteName));

            Font font = _resourceCache.GetResource <FontResource>(@"Fonts/CALIBRI.TTF");

            _name           = new TextSprite("Name", font);
            _name.FillColor = Color.Black;
            _name.Text      = objectName;

            DrawBackground = true;
            DrawBorder     = true;
        }
Esempio n. 7
0
    public AnalysisCom(EntityPrototype proto) : base(proto)
    {
        mEntityType = EntityType.Object;


        Body.mIsKinematic = false;
    }
        public StatisticSystemComp(JSONObject jsonObj)
        {
            this.system = new OverallStatisticSystem();

            for (int i = 0; i < jsonObj.keys.Count; i++)
            {
                if (jsonObj.type != JSONObject.Type.OBJECT)
                {
                    Debug.LogError("StatisticSystemComp was not passed a valid JSONObject to convert to a Prototype");
                    return;
                }

                Entity entity = new EntityPrototype(jsonObj.keys[i], jsonObj.list[i]).Instantiate();

                if (entity.GetComponent <Statistic>() == null)
                {
                    Debug.Log(
                        "StatisticSystemComp was passed a JSONObject for the Statistics"
                        + "which did not give the statistics Statistic components. "
                        + "Adding a Statistic automattically.");
                    entity.AddComponent(new Statistic());
                }

                this.system.AddEntity(entity);
            }
        }
Esempio n. 9
0
    public ItemObject(Item iData, EntityPrototype proto) : base(proto)
    {
        mItemData = iData;

        Body = new PhysicsBody(this, new CustomAABB(Position, new Vector2(5, 5), new Vector2(0, 5)));
        Body.mIsKinematic = false;
        //Body.mState = ColliderState.Closed;
    }
        public static bool HasComponent(this EntityPrototype prototype, Type component, IComponentFactory?componentFactory = null)
        {
            componentFactory ??= IoCManager.Resolve <IComponentFactory>();

            var registration = componentFactory.GetRegistration(component);

            return(prototype.Components.ContainsKey(registration.Name));
        }
Esempio n. 11
0
    public CapturePod(EntityPrototype proto, CaptureGadget gadget) : base(proto)
    {
        this.gadget = gadget;
        mEntityType = EntityType.Object;


        Body.mIsKinematic = true;
    }
Esempio n. 12
0
    public BouncePad(EntityPrototype proto) : base(proto)
    {
        mEntityType = EntityType.Object;


        Body.mIsKinematic = true;
        abilityFlags.SetFlag(AbilityFlag.Heavy, true);
    }
Esempio n. 13
0
 public static IDirectionalTextureProvider GetPrototypeIcon(EntityPrototype prototype, IResourceCache resourceCache)
 {
     if (!prototype.Components.TryGetValue("Icon", out var mapping))
     {
         return(resourceCache.GetFallback <TextureResource>().Texture);
     }
     return(TextureForConfig(YamlObjectSerializer.NewReader(mapping), resourceCache));
 }
Esempio n. 14
0
 public static IRsiStateLike?GetPrototypeIcon(EntityPrototype prototype, IResourceCache resourceCache)
 {
     if (!prototype.Components.TryGetValue("Icon", out var mapping))
     {
         return(null);
     }
     return(TextureForConfig(YamlObjectSerializer.NewReader(mapping), resourceCache));
 }
Esempio n. 15
0
        public static void AddPrototype(EntityPrototype template)
        {
            if (template.GetComponent <Item>() == null)
            {
                Debug.LogError("Any template added to the ItemController should have a Item Component attached.");
            }

            itemPrototypes.Add(template);
        }
Esempio n. 16
0
    public FlowerBed(EntityPrototype proto) : base(proto)
    {
        mEntityType = EntityType.Object;

        Body = new PhysicsBody(this, new CustomAABB(Position, new Vector2(8, 8), new Vector2(0, 8)))
        {
            mIsKinematic = false
        };
    }
Esempio n. 17
0
        public static IRsiStateLike?GetPrototypeIcon(EntityPrototype prototype, IResourceCache resourceCache)
        {
            if (!prototype.Components.TryGetValue("Icon", out var compData))
            {
                return(null);
            }

            return(TextureForConfig((IconComponent)compData, resourceCache));
        }
Esempio n. 18
0
        public static IDirectionalTextureProvider GetPrototypeIcon(EntityPrototype prototype)
        {
            if (!prototype.Components.TryGetValue("Icon", out var mapping))
            {
                return(IoCManager.Resolve <IResourceCache>().GetFallback <TextureResource>().Texture);
            }

            return(TextureForConfig(mapping, prototype));
        }
Esempio n. 19
0
    public void SpawnPlayer(Vector2 position)
    {
        if (pool == null)
        {
            pool = ObjectPool.instance;
        }

        if (Player != null)
        {
            PositionComponent posComp = (PositionComponent)Player.GetEntityComponent(ComponentID.Position);
            posComp.moveData = new MoveData(position.x, position.y);
            EntityGOMap[Player].transform.position = position;
            Player.ChangeActiveStatus(true);
            EntityActionManager.instance.EntityOnTileChanged(Player, posComp.moveData);
            return;
        }

        EntityPrototype proto = GetProtoType("Player");//EntityProtoMap["Player"];

        EntityComponent[] components = ReadProtoComponents(proto.components);

        GameObject entityGO = pool.GetObjectForType("Player", true, position);

        if (entityGO == null)
        {
            // Make a new one?
            return;
        }

        Player = new Entity(proto.Name, proto.entityType, components, isPlayer: true);

        PositionComponent posC = (PositionComponent)Player.GetEntityComponent(ComponentID.Position);

        posC.moveData = new MoveData(position.x, position.y);

        Player.InitComponent(entityGO);

        AbilityComponent abilityComponent = (AbilityComponent)Player.GetEntityComponent(ComponentID.Abilities);

        abilityComponent.AddAbility(AbilityID.Blood_For_Light, true, "25% HP");

        //InventoryComponent inventoryComponent = (InventoryComponent)Player.GetEntityComponent(ComponentID.Inventory);
        //PlayerInputSystem.instance.AddDynamicKeys(() => inventoryComponent.Drop(0), "t");

        Player.ChangeActiveStatus(true);


        EntityGOMap.Add(Player, entityGO);

        Player.CanEndTurnCB = CanPlayerEndTurn;

        // Register input callbacks
        PlayerInputSystem.instance.RegisterOnMoveInputCB((data) => posC.Move(data));

        GetPlayerPositionData += posC.GetPositionData;
    }
Esempio n. 20
0
    public PracticeBot(EntityPrototype proto) : base(proto)
    {
        HurtBox = new Hurtbox(this, new CustomAABB(Position, proto.bodySize, new Vector2(0, proto.bodySize.y)));
        HurtBox.UpdatePosition();
        Body.mIgnoresGravity = proto.ignoreGravity;
        mCollidesWith        = proto.CollidesWith;
        Body.mIsKinematic    = true;

        health = new Health(this, 100);
    }
Esempio n. 21
0
    public Iceblock(EntityPrototype proto) : base(proto)
    {
        Body.mIsKinematic = false;

        mEntityType = EntityType.Obstacle;
        HurtBox     = new Hurtbox(this, new CustomAABB(Position, prototype.bodySize, new Vector2(0, prototype.bodySize.y)));
        HurtBox.UpdatePosition();

        health = new Health(this, 25);
    }
Esempio n. 22
0
 public ForceField(EntityPrototype proto, Player owner, Vector2 offset, ForceFieldGadget gadget) : base(proto)
 {
     this.owner           = owner;
     this.gadget          = gadget;
     ownerOffset          = offset;
     mMovingSpeed         = 0;
     Body.mIgnoresGravity = true;
     shieldBox            = new Blockbox(this, new CustomAABB(Position, proto.bodySize, new Vector2(0, proto.bodySize.y)));
     shieldBox.UpdatePosition();
 }
 public GrapplingHook(EntityPrototype proto, Player owner, Vector2 direction, Vector2 offset, HookShot gadget) : base(proto)
 {
     this.direction       = direction;
     this.owner           = owner;
     this.gadget          = gadget;
     ownerOffset          = offset;
     Body.mIgnoresOneWay  = true;
     mMovingSpeed         = 750;
     Body.mIgnoresGravity = proto.ignoreGravity;
 }
Esempio n. 24
0
    public FallingRock(EntityPrototype proto) : base(proto)
    {
        Body.mSpeed          = Vector2.zero;
        Body.mIsKinematic    = true;
        Body.mIgnoresGravity = true;



        isTriggered = false;
    }
Esempio n. 25
0
    public void SpawnEnemies(string enemyPrototypeName, Vector2[] positions)
    {
        EntityPrototype proto = GetProtoType(enemyPrototypeName); //EntityProtoMap["Enemy"];

        if (proto == null)
        {
            Debug.LogError("EntityManager could not find a protoype called " + enemyPrototypeName + " and cannot spawn it!");
            return;
        }
        int enemyIndex = 0;

        if (Enemies == null || Enemies.Length <= 0)
        {
            Enemies = new Entity[positions.Length];
            Debug.Log("Spawning " + Enemies.Length + " enemies");
        }
        else
        {
            // extend enemies
            Entity[] origEnemies = Enemies;
            Enemies = new Entity[origEnemies.Length + positions.Length];
            for (int i = 0; i < origEnemies.Length; i++)
            {
                Enemies[i] = origEnemies[i];
            }
            enemyIndex = origEnemies.Length;
        }

        int posIndex = 0;

        for (int i = enemyIndex; i < Enemies.Length; i++)
        {
            GameObject entityGO = pool.GetObjectForType("Entity", true, positions[posIndex]);
            if (entityGO == null)
            {
                // Make a new one?
                return;
            }
            EntityComponent[] components = ReadProtoComponents(proto.components);
            Entity            newEntity  = new Entity(proto.Name, proto.entityType, components);

            PositionComponent posC = (PositionComponent)newEntity.GetEntityComponent(ComponentID.Position);
            posC.moveData = new MoveData(positions[posIndex].x, positions[posIndex].y);

            newEntity.InitComponent(entityGO);

            EntityGOMap.Add(newEntity, entityGO);
            int index = i;
            // Register end turn CB for enemy
            newEntity.CanEndTurnCB = () => CanEnemyEndTurn(index);
            Enemies[i]             = newEntity;

            posIndex++;
        }
    }
    public BreakableTile(EntityPrototype proto) : base(proto)
    {
        Body    = new PhysicsBody(this, new CustomAABB(Position, proto.bodySize, Vector2.zero));
        HurtBox = new Hurtbox(this, new CustomAABB(Position, proto.bodySize, Vector2.zero));
        HurtBox.UpdatePosition();
        Body.mIgnoresGravity = proto.ignoreGravity;
        mCollidesWith        = proto.CollidesWith;
        Body.mIsKinematic    = true;

        health = new Health(this, 15);
    }
 public void Clear()
 {
     CurrentBaseSprite = null;
     CurrentPrototype  = null;
     CurrentPermission = null;
     CurrentMode       = null;
     if (PlacementCanceled != null && IsActive && !Eraser)
     {
         PlacementCanceled(this, null);
     }
     IsActive = false;
     Eraser   = false;
 }
Esempio n. 28
0
    public Spikes(EntityPrototype proto) : base(proto)
    {
        mEntityType = EntityType.Object;

        Body = new PhysicsBody(this, new CustomAABB(Position, proto.bodySize, new Vector2(0, 0)));

        Body.mIsKinematic = false;

        if (Random.Range(0, 10) >= 8)
        {
            locked = true;
        }
    }
Esempio n. 29
0
        private static bool _doesPrototypeMatchSearch(EntityPrototype prototype, string searchStr)
        {
            if (prototype.ID.ToLowerInvariant().Contains(searchStr))
            {
                return(true);
            }

            if (prototype.Name.ToLowerInvariant().Contains(searchStr))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 30
0
        public DataNode Write(ISerializationManager serializationManager, SpriteSpecifier value, bool alwaysWrite = false,
                              ISerializationContext?context = null)
        {
            return(value switch
            {
                Rsi rsi
                => Write(serializationManager, rsi, alwaysWrite, context),

                Texture texture
                => Write(serializationManager, texture, alwaysWrite, context),

                EntityPrototype entityPrototype
                => Write(serializationManager, entityPrototype, alwaysWrite, context),

                _ => throw new InvalidOperationException("Invalid SpriteSpecifier specified!")
            });