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); }
public SaveMachine(EntityPrototype proto) : base(proto) { mEntityType = EntityType.Object; Body.mIsKinematic = false; }
public NavSystem(EntityPrototype proto) : base(proto) { mEntityType = EntityType.Object; Body.mIsKinematic = false; }
public MedicalBay(EntityPrototype proto) : base(proto) { mEntityType = EntityType.Object; Body.mIsKinematic = false; }
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; }
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); } }
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)); }
public CapturePod(EntityPrototype proto, CaptureGadget gadget) : base(proto) { this.gadget = gadget; mEntityType = EntityType.Object; Body.mIsKinematic = true; }
public BouncePad(EntityPrototype proto) : base(proto) { mEntityType = EntityType.Object; Body.mIsKinematic = true; abilityFlags.SetFlag(AbilityFlag.Heavy, true); }
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)); }
public static IRsiStateLike?GetPrototypeIcon(EntityPrototype prototype, IResourceCache resourceCache) { if (!prototype.Components.TryGetValue("Icon", out var mapping)) { return(null); } return(TextureForConfig(YamlObjectSerializer.NewReader(mapping), resourceCache)); }
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); }
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 }; }
public static IRsiStateLike?GetPrototypeIcon(EntityPrototype prototype, IResourceCache resourceCache) { if (!prototype.Components.TryGetValue("Icon", out var compData)) { return(null); } return(TextureForConfig((IconComponent)compData, resourceCache)); }
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)); }
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; }
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); }
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); }
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; }
public FallingRock(EntityPrototype proto) : base(proto) { Body.mSpeed = Vector2.zero; Body.mIsKinematic = true; Body.mIgnoresGravity = true; isTriggered = false; }
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; }
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; } }
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); }
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!") });