public void AddRoom(int x, int y, int w, int h) { for (int i = x; i < x + w; i++) { FEntity wall = Instantiate(objectEntityPrefab); wall.Setup(); wall.name = "Wall"; wall.GetComponent <RenderComponent>().SetData("wall_bottom", new Color32(146, 126, 106, 255)); wall.AddComponent("MovementBlockComponent"); wall.AddComponent("BlockVisionComponent"); entityList.Add(wall); map.PutEntityAt(wall, i, y); map.ClearFloorAt(i, y); wall.PropagateEvent(new FEvent(FEventCodes.ENTITY_SPAWN, "x", i, "y", y)); wall = Instantiate(objectEntityPrefab); wall.Setup(); wall.name = "Wall"; wall.GetComponent <RenderComponent>().SetData("wall_bottom", new Color32(146, 126, 106, 255)); wall.AddComponent("MovementBlockComponent"); wall.AddComponent("BlockVisionComponent"); entityList.Add(wall); map.PutEntityAt(wall, i, y + h - 1); map.ClearFloorAt(i, y + h - 1); wall.PropagateEvent(new FEvent(FEventCodes.ENTITY_SPAWN, "x", i, "y", y + h - 1)); } for (int i = y; i < y + h; i++) { FEntity wall = Instantiate(objectEntityPrefab); wall.Setup(); wall.name = "Wall"; wall.GetComponent <RenderComponent>().SetData("wall_bottom", new Color32(146, 126, 106, 255)); wall.AddComponent("MovementBlockComponent"); wall.AddComponent("BlockVisionComponent"); entityList.Add(wall); map.PutEntityAt(wall, x, i); map.ClearFloorAt(x, i); wall.PropagateEvent(new FEvent(FEventCodes.ENTITY_SPAWN, "x", x, "y", i)); wall = Instantiate(objectEntityPrefab); wall.Setup(); wall.name = "Wall"; wall.GetComponent <RenderComponent>().SetData("wall_bottom", new Color32(146, 126, 106, 255)); wall.AddComponent("MovementBlockComponent"); wall.AddComponent("BlockVisionComponent"); entityList.Add(wall); map.PutEntityAt(wall, x + w - 1, i); map.ClearFloorAt(x + w - 1, i); wall.PropagateEvent(new FEvent(FEventCodes.ENTITY_SPAWN, "x", x + w - 1, "y", i)); } }
public bool TryMoveEntity(FEntity ch, int tox, int toy) { FEvent moveIntoEvent = new FEvent(FEventCodes.ENTITY_TRY_MOVE_INTO); moveIntoEvent.Add("x", tox); moveIntoEvent.Add("y", toy); moveIntoEvent.Add("entity", ch); moveIntoEvent.Add("moveCancelled", false); FEvent loc1 = ch.PropagateEvent(new FEvent(FEventCodes.GET_LOCATION, "x", -1, "y", -1)); int dist = Mathf.Max(Mathf.Abs((int)loc1.Get("x") - tox), Mathf.Abs((int)loc1.Get("y") - toy)); if (dist > 1) { Debug.Log(loc1.Get("x") + "," + loc1.Get("y")); List <MapTile> tiles = GameMap.instance.PathToFrom((int)loc1.Get("x"), (int)loc1.Get("y"), tox, toy); Debug.Log(tiles[0].x + "," + tiles[0].y); return(TryMoveEntity(ch, tiles[0].x, tiles[0].y)); } List <FEntity> entitiesAtNewLocation = map.GetEntitiesAt(tox, toy); foreach (FEntity entity in entitiesAtNewLocation) { moveIntoEvent = entity.PropagateEvent(moveIntoEvent); } if ((bool)moveIntoEvent.Get("moveCancelled")) { //Nope if (moveIntoEvent.Get("moveBlockedByEntity") != null) { //End turn FEntity entity = (FEntity)moveIntoEvent.Get("blockingEntity"); FEvent meleeAttack = ch.PropagateEvent(new FEvent(FEventCodes.ENTITY_MELEE_ATTACK, "target", entity, "damage", 0)); } EndTurn(); return(false); } FEvent moveEvent = new FEvent(FEventCodes.ENTITY_MOVE); moveEvent.Add("x", tox); moveEvent.Add("y", toy); moveEvent = ch.PropagateEvent(moveEvent); EndTurn(); return(true); }
public override FEvent PropagateEvent(FEvent ev) { if (ev.eventName == FEventCodes.ENTITY_RECEIVE_MELEE_ATTACK) { FEntity attacker = ev.Get("attacker") as FEntity; attacker.PropagateEvent(new FEvent(FEventCodes.ENTITY_RECEIVE_MAGICAL_ATTACK, "damage", thornsAmount, "attacker", parentEntity, "element", Stat.ELEMENT.NONE)); } return(ev); }
public override FEvent PropagateEvent(FEvent ev) { if (ev.eventName == FEventCodes.ENTITY_MELEE_ATTACK) { FEntity target = (FEntity)ev.Get("target"); FEvent nameEvent = parentEntity.PropagateEvent(new FEvent(FEventCodes.GET_ENTITY_NAME, "name", "????")); string ourName = (string)nameEvent.Get("fullstring"); nameEvent = target.PropagateEvent(new FEvent(FEventCodes.GET_ENTITY_NAME, "name", "????")); string theirName = (string)nameEvent.Get("fullstring"); MessageLog.instance.Log(ourName + " attacks the " + theirName + "!"); target.PropagateEvent(new FEvent(FEventCodes.ENTITY_RECEIVE_MELEE_ATTACK, "attacker", this.parentEntity, "damage", (int)ev.Get("damage"))); } return(ev); }
public override FEvent PropagateEvent(FEvent ev) { if (ev.eventName == FEventCodes.ENTITY_MELEE_ATTACK) { FEntity target = ev.Get("target") as FEntity; target.PropagateEvent(new FEvent(FEventCodes.INFLICT_BLEEDING)); } return(ev); }
public int StraightLineDistanceBetween(FEntity e1, FEntity e2) { // LocationComponent l1 = e1.GetComponent<LocationComponent>(); // LocationComponent l2 = e2.GetComponent<LocationComponent>(); FEvent loc1 = e1.PropagateEvent(new FEvent(FEventCodes.GET_LOCATION, "x", -1, "y", -1)); FEvent loc2 = e2.PropagateEvent(new FEvent(FEventCodes.GET_LOCATION, "x", -1, "y", -1)); return(Mathf.Max(Mathf.Abs(((int)loc1.Get("x") - ((int)loc2.Get("x")))), ((int)loc1.Get("y") - ((int)loc2.Get("y"))))); // return (e1.gameObject.transform.position-e2.gameObject.transform.position).magnitude; }
public override FEvent PropagateEvent(FEvent ev) { if (ev.eventName == FEventCodes.ENTITY_MELEE_ATTACK && Random.Range(0f, 1f) < mugChance) { FEntity target = (FEntity)ev.Get("target"); List <FEntity> targetCarries = target.PropagateEvent(new FEvent(FEventCodes.GET_CARRIED_LIST, "list", new List <FEntity>())).Get("list") as List <FEntity>; if (targetCarries.Count > 0) { FEntity stolenItem = targetCarries[Random.Range(0, targetCarries.Count)]; //Take the item target.PropagateEvent(new FEvent(FEventCodes.TRY_PICK_UP_OBJECT, "object", stolenItem)); stolenItem.PropagateEvent(new FEvent(FEventCodes.PICKED_UP, "carrier", parentEntity)); parentEntity.PropagateEvent(new FEvent(FEventCodes.RECEIVE_ITEM, "item", stolenItem)); Debug.Log("Stolen item"); // MessageLog.instance.Log("") } } return(ev); }
public void EndTurn() { UpdateInterface(); markedForRemoval = new List <FEntity>(); FEntity entity = null; for (int i = 0; i < nonPlayerAgents.Count; i++) { entity = nonPlayerAgents[i]; entity.PropagateEvent(new FEvent(FEventCodes.TAKE_TURN)); } //Everyone's acted, now: for (int i = 0; i < nonPlayerAgents.Count; i++) { entity = nonPlayerAgents[i]; entity.PropagateEvent(new FEvent(FEventCodes.END_TURN)); } playerEntity.PropagateEvent(new FEvent(FEventCodes.END_TURN)); for (int i = 0; i < markedForRemoval.Count; i++) { entity = markedForRemoval[i]; if (entityList.Contains(entity)) { entityList.Remove(entity); } if (nonPlayerAgents.Contains(entity)) { nonPlayerAgents.Remove(entity); } Destroy(entity.gameObject); } ProcessSpawnRequests(); ClearSpawnRequests(); GameMap.instance.UpdateVisionCone(playerEntity); MessageLog.turn++; }
public void RemoveEntityAt(FEntity entity) { FEvent loc = entity.PropagateEvent(new FEvent(FEventCodes.GET_LOCATION, "x", -1, "y", -1)); string key = ((int)loc.Get("x")) + "," + ((int)loc.Get("y")); if (!entityLocationMap.ContainsKey(key)) { // Debug.Log("Could not find item"); return; } entityLocationMap[key].Remove(entity); }
public void DrinkSelected() { if (selectedInventoryItem == null || !selectedInventoryItem.HasComponent(typeof(Drinkable))) { return; } string _n = selectedInventoryItem.PropagateEvent(new FEvent(FEventCodes.GET_ENTITY_NAME)).Get("name") as string; MessageLog.instance.Log("You drink the " + _n + "."); FEvent drink = selectedInventoryItem.PropagateEvent(new FEvent(FEventCodes.DRINK, "drinker", playerEntity, "consumed", false)); if ((bool)drink.Get("consumed")) { inventory.Remove(selectedInventoryItem); playerEntity.PropagateEvent(new FEvent(FEventCodes.CONSUME_ITEM, "item", selectedInventoryItem)); } selectedInventoryItem = null; selectedIndex = -1; ItemListWindow.instance.RefreshWindow(inventory); }
/* * Potions were one of the last things I implemented before stopping on the example. This is a good example of a branch * point for detail in an ECS. A potion could be a container filled with a liquid, and the liquid has effects when it * touches things (the floor, a human, a zombie). However that felt too detailed/granular, so instead potions are things * that can be drunk or thrown, and then apply affects to the things they're drunk by or thrown at. So you can't find * a fountain of healing liquid or find someone who cries tears of healing (or maybe you could but it'd be another case * rather than reusing the same healing liquid in a new context). */ public override FEvent PropagateEvent(FEvent ev) { if (ev.eventName == FEventCodes.DRINK) { //INGEST FEntity drinker = ev.Get("drinker") as FEntity; drinker.PropagateEvent(new FEvent(FEventCodes.HEAL_HP, "amount", 5)); } else if (ev.eventName == FEventCodes.CONTAINER_BREAK) { //BROKE GameMap.instance.PropagateEventToTile(new FEvent(FEventCodes.HEAL_HP, "amount", 5), parentEntity, true); } return(ev); }
/* * A neat thing I saw in Alexei Peper's Nethack talk, which is that Nethack's print command is * called "You" so the code reads You("kill the beast"). I thought that was really cute. */ public string You(string message) { FEvent name = parentEntity.PropagateEvent(new FEvent(FEventCodes.GET_ENTITY_NAME)); return((name.Get("fullstring") as string) + " " + message); }
/* * Brian Bucklew's talk on ECS shows how objects are built from simple prototypes, and I've seen similar in * Roguelike Celebration talks about ADOM and other RLs. My original idea was not to use Unity's built-in ECS, * which would've let me use proper constructors and stuff, but since I use MonoBehaviours I can't really do * that, so we have this somehwat clumsier approach to prototyping. * * I imagine there's a nicer way of doing this - ScriptableObjects maybe, that MonoBehaviour-but-not class Unity * has that I forget about all the time. This works fine here. If you wanted to make your thing bigger, you'd * probably want a nicer way of defining these (one of the nice things about Brian's approach is that prototypes * can be specified in XML and thus edited outside of code mode). */ public FEntity SpawnPrototype(string name, int x, int y) { FEntity res = null; GameObject go = new GameObject(name); go.tag = "Entity"; res = go.AddComponent <FEntity>(); res.Setup(); if (name == "blood_spatter") { res.AddComponent("RenderComponent", "splatter_" + Random.Range(1, 4), new Color32(126, 37, 83, 255)); res.GetComponent <RenderComponent>().SetSpriteLayer("Stage BG", 2); res.AddComponent("LocationComponent", x, y); } if (name == "fire") { res.AddComponent("RenderComponent", "fire", new Color32(255, 163, 0, 255)); res.GetComponent <RenderComponent>().SetSpriteLayer("Stage BG", 5); res.AddComponent("LocationComponent", x, y); res.AddComponent("FireComponent"); } if (name == "grass") { res.AddComponent("RenderComponent", "grass" + Random.Range(1, 4), new Color32(0, 135, 81, 255)); res.GetComponent <RenderComponent>().SetSpriteLayer("Stage BG", 0); res.AddComponent("LocationComponent", x, y); res.AddComponent("Flammable"); } if (name == "armor") { res.AddComponent("NameComponent", "leather armor", "ffffff"); res.AddComponent(res.gameObject.AddComponent <ArmorComponent>()); res.AddComponent(res.gameObject.AddComponent <CanCarry>()); res.AddComponent(res.gameObject.AddComponent <Equippable>()); res.AddComponent("LocationComponent", x, y); } if (name == "sword") { res.AddComponent("NameComponent", "short sword", "ffffff"); res.AddComponent(res.gameObject.AddComponent <MeleeWeaponComponent>()); res.AddComponent(res.gameObject.AddComponent <CanCarry>()); res.AddComponent(res.gameObject.AddComponent <Equippable>()); res.AddComponent(res.gameObject.AddComponent <Throwable>()); res.AddComponent("RenderComponent", "sword", new Color32(150, 150, 150, 255)); res.AddComponent("LocationComponent", x, y); } if (name == "healingpotion") { res.Setup(); res.AddComponent("LocationComponent", x, y); res.AddComponent("NameComponent", "healing potion", "FF77A8"); res.AddComponent("RenderComponent", "potion", new Color32(57, 87, 28, 255), 5); res.AddComponent("Throwable"); res.AddComponent("CanCarry"); res.AddComponent("LocationComponent"); res.AddComponent("Drinkable"); res.AddComponent("HealingPotionEffect"); res.AddComponent("PotionComponent"); } if (name == "skeleton_fighter") { res.name = "Skeleton"; res.AddComponent("RenderComponent", "skeleton", (Color32) new Color(0.764f, 0.639f, 0.541f, 1f)); res.AddComponent("LocationComponent", x, y); res.AddComponent(res.gameObject.AddComponent <MonsterComponent>()); res.gameObject.GetComponent <MonsterComponent>().deathSpriteName = "pile_of_bones"; res.AddComponent("NameComponent", "skeleton warrior", "997577"); res.AddComponent(res.gameObject.AddComponent <MeleeCombatComponent>()); res.AddComponent(res.gameObject.AddComponent <MonsterAIComponent>()); res.AddComponent("EquipSlotsComponent"); res.AddComponent("InventoryComponent"); res.AddComponent("StatBlockComponent"); GameObject swordObj = new GameObject("Sword"); swordObj.tag = "Entity"; FEntity sword = swordObj.AddComponent <FEntity>(); sword.Setup(); sword.AddComponent("NameComponent", "short sword", "ffffff"); sword.AddComponent("RenderComponent", "sword", new Color32(150, 150, 150, 255)); sword.AddComponent("LocationComponent"); sword.AddComponent("CanCarry"); sword.AddComponent("MeleeWeaponComponent"); sword.AddComponent("RustyWeaponComponent"); sword.AddComponent("Equippable"); EquipSlotsComponent esc = res.GetComponent <EquipSlotsComponent>(); esc.AddSlot("LeftHand"); sword.PropagateEvent(new FEvent(FEventCodes.PICKED_UP, "carrier", res)); res.PropagateEvent(new FEvent(FEventCodes.RECEIVE_ITEM, "item", sword)); // res.PropagateEvent(new FEvent(FEventCodes.EQUIP_ITEM, "item", sword, "slotName", "LeftHand")); } return(res); }
public override FEvent PropagateEvent(FEvent ev) { if (ev.eventName == FEventCodes.GET_NAME_MODIFIERS || ev.eventName == FEventCodes.GET_LOCATION) { return(ev); } if (ev.eventName == FEventCodes.ENTITY_DIED) { foreach (EntitySlot slot in slots.Values) { if (slot.slot != null) { parentEntity.PropagateEvent(new FEvent(FEventCodes.UNEQUIP_ITEM, "item", slot.slot)); } } } if (ev.eventName == FEventCodes.DISARM_WEAPON) { List <FEntity> weapons = new List <FEntity>(); //What can be disarmed? foreach (EntitySlot slot in slots.Values) { if (slot.slot != null && slot.slot.HasComponent(typeof(MeleeWeaponComponent))) { weapons.Add(slot.slot); } } if (weapons.Count > 0) { FEntity disarmTarget = weapons[Random.Range(0, weapons.Count)]; parentEntity.PropagateEvent(new FEvent(FEventCodes.UNEQUIP_ITEM, "item", disarmTarget)); FEvent lev = parentEntity.PropagateEvent(new FEvent(FEventCodes.GET_LOCATION, "x", -1, "y", -1)); parentEntity.PropagateEvent(new FEvent(FEventCodes.LOSE_ITEM, "item", disarmTarget, "x", (int)lev.Get("x"), "y", (int)lev.Get("y"))); disarmTarget.PropagateEvent(new FEvent(FEventCodes.DROP_ITEM_HERE, "item", disarmTarget, "x", (int)lev.Get("x"), "y", (int)lev.Get("y"))); FEvent name = disarmTarget.PropagateEvent(new FEvent(FEventCodes.GET_ENTITY_NAME)); MessageLog.instance.Log(You("drop the " + name.Get("fullstring") as string)); } return(ev); } if (ev.eventName == FEventCodes.ENTITY_SPAWN || ev.eventName == FEventCodes.GET_ENTITY_NAME) { //Ok so we clearly need better logic to determine what events propagate to children. return(ev); } foreach (EntitySlot slot in slots.Values) { if (slot.slot != null) { ev = slot.slot.PropagateEvent(ev); } } // if(ev.eventName == FEventCodes.TRY_PICK_UP_OBJECT){ // FEntity entity = ev.Get("object") as FEntity; // foreach(EntitySlot slot in slots.Values){ // if(slot.slot != null && slot.slot == entity){ // slot.slot = null; // entity.PropagateEvent(new FEvent(FEventCodes.WAS_UNEQUIPPED)); // } // } // } if (ev.eventName == FEventCodes.EQUIP_ITEM) { string sn = ev.Get("slotName") as string; if (sn == null) { Debug.LogWarning("No slot provided for equip request"); foreach (EntitySlot s in slots.Values) { if (s.slot == null) { sn = s.slotName; } } } if (sn == null) { return(ev); } FEntity en = ev.Get("item") as FEntity; if (EquipInSlot(sn, en)) { en.PropagateEvent(new FEvent(FEventCodes.WAS_EQUIPPED)); } } if (ev.eventName == FEventCodes.UNEQUIP_ITEM) { FEntity en = ev.Get("item") as FEntity; foreach (EntitySlot slot in slots.Values) { if (slot.slot != null && slot.slot == en) { slot.slot = null; en.PropagateEvent(new FEvent(FEventCodes.WAS_UNEQUIPPED)); } } } //This is actually identical to unequipping it, but I duplicated it for clarity >_> if (ev.eventName == FEventCodes.LOSE_ITEM) { FEntity en = ev.Get("item") as FEntity; foreach (EntitySlot slot in slots.Values) { if (slot.slot != null && slot.slot == en) { slot.slot = null; en.PropagateEvent(new FEvent(FEventCodes.WAS_UNEQUIPPED)); } } } if (ev.eventName == FEventCodes.GET_WIELDED_LIST) { List <FEntity> names = (List <FEntity>)ev.Get("list"); foreach (EntitySlot slot in slots.Values) { if (slot.slot == null) { continue; } names.Add(slot.slot); } ev.Set("list", names); } return(ev); }
public string GetPosition(FEntity entity) { FEvent loc = entity.PropagateEvent(new FEvent(FEventCodes.GET_LOCATION, "x", -1, "y", -1)); return(((int)loc.Get("x")) + "," + ((int)loc.Get("y"))); }
public Vector3 GetMapLocation(FEntity entity) { FEvent loc = entity.PropagateEvent(new FEvent(FEventCodes.GET_LOCATION, "x", -1, "y", -1)); return(GetMapLocation(((int)loc.Get("x")), ((int)loc.Get("y")))); }
public int[] GetGridLocation(FEntity entity) { FEvent loc = entity.PropagateEvent(new FEvent(FEventCodes.GET_LOCATION, "x", -1, "y", -1)); return(new int[] { (int)loc.Get("x"), (int)loc.Get("y") }); }
public void CAMap(float irand, int iter, int min, int max) { bool[,] bmap = new bool[worldWidth, worldHeight]; for (int i = 0; i < worldWidth; i++) { for (int j = 0; j < worldHeight; j++) { bmap[i, j] = Random.Range(0f, 1f) < irand; } } for (int it = 0; it < iter; it++) { bool[,] nmap = new bool[worldWidth, worldHeight]; for (int i = 0; i < worldWidth; i++) { for (int j = 0; j < worldHeight; j++) { int n = cnt_nbs(bmap, i, j); if (!bmap[i, j]) { nmap[i, j] = n > 4; } else { nmap[i, j] = n >= 4; } } } bmap = nmap; } for (int i = 0; i < worldWidth; i++) { for (int j = 0; j < worldHeight; j++) { if (bmap[i, j] || i == 0 || j == 0 || i == worldWidth - 1 || j == worldHeight - 1) { bmap[i, j] = true; FEntity wall = Instantiate(objectEntityPrefab); wall.Setup(); wall.name = "Wall"; string spr = "wall_main"; if (j > 0 && !bmap[i, j - 1]) { spr = "rockwall" + Random.Range(1, 4); } if (i == 0 || i == worldWidth - 1) { spr = "wall_main"; } wall.GetComponent <RenderComponent>().SetData(spr, new Color32(146, 126, 106, 255)); wall.AddComponent("MovementBlockComponent"); wall.AddComponent("BlockVisionComponent"); entityList.Add(wall); map.PutEntityAt(wall, i, j); map.ClearFloorAt(i, j); wall.PropagateEvent(new FEvent(FEventCodes.ENTITY_SPAWN, "x", i, "y", j)); } } } map_draft = bmap; }
public override FEvent PropagateEvent(FEvent ev) { if (ev.eventName == FEventCodes.PICKED_UP) { //Shadow the location component of the picker-upper carrier = ev.Get("carrier") as FEntity; carried = true; GameMap.instance.RemoveEntityAt(parentEntity); } if (ev.eventName == FEventCodes.THROWN) { carried = false; carrier = null; this.x = (int)ev.data["x"]; this.y = (int)ev.data["y"]; transform.position = GameMap.instance.GetMapLocation(x, y); GameMap.instance.PutEntityAt(parentEntity, x, y); parentEntity.PropagateEvent(new FEvent(FEventCodes.POSITION_CHANGED, "x", x, "y", y)); } if (ev.eventName == FEventCodes.DROP_ITEM_HERE) { carried = false; carrier = null; this.x = (int)ev.data["x"]; this.y = (int)ev.data["y"]; Debug.Log("Dropping"); transform.position = GameMap.instance.GetMapLocation(x, y); GameMap.instance.PutEntityAt(parentEntity, x, y); parentEntity.PropagateEvent(new FEvent(FEventCodes.POSITION_CHANGED, "x", x, "y", y)); } if (ev.eventName == FEventCodes.GET_LOCATION) { if (!carried) { ev.Set("x", this.x); ev.Set("y", this.y); } else { Debug.Assert(carrier != parentEntity); FEvent subloc = carrier.PropagateEvent(new FEvent(FEventCodes.GET_LOCATION, "x", -1, "y", -1)); ev.Set("x", (int)subloc.Get("x")); ev.Set("y", (int)subloc.Get("y")); } } if (ev.eventName == FEventCodes.ENTITY_SPAWN) { this.x = (int)ev.data["x"]; this.y = (int)ev.data["y"]; transform.position = GameMap.instance.GetMapLocation(x, y); parentEntity.PropagateEvent(new FEvent(FEventCodes.POSITION_CHANGED, "x", x, "y", y)); } else if (ev.eventName == FEventCodes.ENTITY_MOVE && !carried) { int nx = (int)ev.data["x"]; int ny = (int)ev.data["y"]; transform.DOMove(GameMap.instance.GetMapLocation(nx, ny), 0.25f); GameMap.instance.ChangeMapLocation(parentEntity, nx, ny); this.x = nx; this.y = ny; parentEntity.PropagateEvent(new FEvent(FEventCodes.POSITION_CHANGED, "x", x, "y", y)); } return(ev); }
public bool TryMoveEntityRelative(FEntity entity, int dx, int dy) { FEvent loc = entity.PropagateEvent(new FEvent(FEventCodes.GET_LOCATION, "x", -1, "y", -1)); return(TryMoveEntity(entity, dx + ((int)loc.Get("x")), dy + ((int)loc.Get("y")))); }
public void SetupDungeon() { CAMap(0.465f, 2, 4, 5); Print(map_draft); List <MapTile> region = FindLargestRegion(map_draft); playerEntity = Instantiate(actorEntityPrefab); playerEntity.Setup(); RenderComponent rc = playerEntity.GetComponent <RenderComponent>(); rc.SetSprite(spriteManager.GetSpriteByName("knight")); rc.GetComponent <RenderComponent>().SetColor(new Color(0.964f, 0.839f, 0.741f, 1f)); playerEntity.AddComponent(playerEntity.gameObject.AddComponent <MeleeCombatComponent>()); playerEntity.AddComponent(playerEntity.gameObject.AddComponent <PlayerComponent>()); NameComponent nc = playerEntity.GetComponent <NameComponent>(); nc.SetData("Player", "c3a38a"); playerEntity.AddComponent(nc); playerEntity.AddComponent("OrganicCreature"); CameraTrackObject.instance.trackObject = playerEntity.gameObject; EquipSlotsComponent esc = playerEntity.GetComponent <EquipSlotsComponent>(); esc.AddSlot("LeftHand"); esc.AddSlot("Chest"); entityList.Add(playerEntity); MapTile start = region[Random.Range(0, region.Count)]; map.PutEntityAt(playerEntity, start.x, start.y); playerEntity.PropagateEvent(new FEvent(FEventCodes.ENTITY_SPAWN, "x", start.x, "y", start.y)); FEntity sword = GambitPrototypes.instance.SpawnPrototype("sword", -1, -1); sword.PropagateEvent(new FEvent(FEventCodes.PICKED_UP, "carrier", playerEntity)); playerEntity.PropagateEvent(new FEvent(FEventCodes.RECEIVE_ITEM, "item", sword)); playerEntity.PropagateEvent(new FEvent(FEventCodes.EQUIP_ITEM, "item", sword, "slotName", "LeftHand")); FEntity armor = GambitPrototypes.instance.SpawnPrototype("armor", -1, -1); //Player can't die. armor.AddComponent("InvulnerableComponent"); armor.PropagateEvent(new FEvent(FEventCodes.PICKED_UP, "carrier", playerEntity)); playerEntity.PropagateEvent(new FEvent(FEventCodes.RECEIVE_ITEM, "item", armor)); playerEntity.PropagateEvent(new FEvent(FEventCodes.EQUIP_ITEM, "item", armor, "slotName", "Chest")); nonPlayerAgents = new List <FEntity>(); for (int i = 0; i < 10; i++) { start = region[Random.Range(0, region.Count)]; SpawnPrototypeAt("skeleton_fighter", start.x, start.y); } for (int i = 0; i < 5; i++) { start = region[Random.Range(0, region.Count)]; SpawnPrototypeAt("healingpotion", start.x, start.y); } for (int i = 0; i < 20; i++) { start = region[Random.Range(0, region.Count)]; SpawnPrototypeAt("grass", start.x, start.y); } }