private void addItemDatatoList(TWItemScript item, List <ItemData> list) { ItemData tmpId = ScriptableObject.CreateInstance <ItemData>(); tmpId.setItem(item); list.Add(tmpId); }
public override void tick(TWItemScript father) { float t = 0.02f * Time.deltaTime; if (Random.Range(0f, 1f) < t) { Cell[] vecinas = ((Cell)father.Entity.Position).Map.getNeightbours(((Cell)father.Entity.Position)); List <Cell> vecinasUsables = new List <Cell>(); foreach (Cell v in vecinas) { if (v != null && v.getEntities().Length == 0) { vecinasUsables.Add(v); } } if (vecinasUsables.Count > 0) { Cell cs = vecinasUsables[Random.Range(0, vecinasUsables.Count)]; //TWItem item; if (Random.Range(0, 2) == 0) { TWItem.instanceItem("Palo", cs); } else { TWItem.instanceItem("Hoja", cs); } } } }
private void addItemDatatoList(TWItemScript item, Cell pos, List <ItemData> list) { ItemData tmpId = ScriptableObject.CreateInstance <ItemData>(); tmpId.setItem(item); tmpId.Coords = pos.Map.getCoords(pos.gameObject); list.Add(tmpId); }
//Static functions public static TWItemScript instanceItem(string itemname, Cell position) { TWItem item = Instantiate(Resources.Load <TWItem>(itemname)); GameObject gp = position.addDecoration(new Vector3(0, 0, 0), 0, false, true, item.Representation); Entity enp = gp.AddComponent <Entity>(); TWItemScript itp = gp.AddComponent <TWItemScript>(); itp.item = item; enp.Position = position; position.Map.registerEntity(enp); return(itp); }
public override void tick(TWItemScript father) { float t = 0.05f * Time.deltaTime; if (Random.Range(0f, 1f) < t) { mytick++; if (mytick >= 1) { TWItem.instanceItem("Arbol", (Cell)father.Entity.Position).Entity.isBlackList = false; TWItem.destroyItem(father); } } }
public bool canPick(TWItemScript item) { MinionScript minion = this.GetComponent <MinionScript>(); bool pickable = false; if (hayHueco(item.item)) { int it = item.item.Peso, man = this.pesoManos(), fu = minion.maxFuerza; if ((it + man) < fu) { pickable = true; } } return(pickable); }
public static void destroyItem(TWItemScript item) { Cell cs = null; if (item.Entity.Position is Cell) { cs = (Cell)item.Entity.Position; } else { cs = (Cell)((Entity)item.Entity.Position).Position; } cs.Map.unRegisterEntity(item.Entity); Component.Destroy(item.Entity); Component.Destroy(item); GameObject.DestroyImmediate(item.gameObject); }
public ItemData setItem(TWItemScript source) { this.id = source.GetInstanceID(); Cell tmp; if (source.Entity.Position is Cell) { tmp = ((Cell)source.Entity.Position); } else //if (source.Entity.Position is Entity) { tmp = (Cell)((Entity)source.Entity.Position).Position; } this.coords = tmp.Map.getCoords(tmp.gameObject); this.nombre = source.item.Name; this.peso = source.item.Peso; if (source.Entity.Position is Entity) { manos = ((Entity)source.Entity.Position).GetComponent <Hands> (); } return(this); }
public override void tick(TWItemScript father) { }
public abstract void tick(TWItemScript father);
// Update is called once per frame void Update() { if (my_transform == null) { my_transform = this.transform; } if (!Application.isPlaying && Application.isEditor) { Transform parent = my_transform.parent; Transform actual = null; if (position != null) { if (position is Cell) { actual = ((Cell)position).transform; } else { actual = ((Entity)position).transform; } } if (parent != actual) { if (parent.GetComponent <Cell>() != null) { Cell probablyParent = parent.GetComponent <Cell>(); if (probablyParent != null) { position = probablyParent; } else if (actual != null) { my_transform.parent = actual; } } else if (parent.GetComponent <Entity>() != null) { Entity probablyParent = parent.GetComponent <Entity>(); if (probablyParent != null) { position = probablyParent; } else if (actual != null) { my_transform.parent = actual; } } } if (this.position != null) { if (position is Cell) { my_transform.position = ((Cell)position).transform.position + new Vector3(0, ((Cell)position).WalkingHeight + my_transform.localScale.y / 2f, 0); } else if (position is Entity) { Entity tmp = (Entity)position; Hands manos = ((Entity)position).GetComponent <Hands>(); float xmod = 0f, ymod = this.transform.localScale.y; if (manos != null) { TWItemScript itm = this.GetComponent <TWItemScript>(); if (manos.leftHand == itm && manos.rightHand == itm) { ymod = this.transform.localScale.y / 2; } else if (manos.leftHand == itm) { ymod = -this.transform.localScale.y / 3; xmod = -(((Entity)position).transform.localScale.x) / 3; } else if (manos.rightHand == itm) { ymod = -this.transform.localScale.y / 3; xmod = (((Entity)position).transform.localScale.x) / 3; } } this.transform.parent = tmp.transform; this.transform.localPosition = new Vector3(xmod, ymod, -0.01f); } } } }
public GameEvent use(Object[] itm) { GameEvent ge = GameEvent.CreateInstance <GameEvent>(); ge.Name = "UseReport"; TWItemScript[] items = haveTheItems(itm); if (items == null) { ge.setParameter("result", "donthave"); return(ge); } List <ItemData> nuevos = new List <ItemData>(), noHanCambiado = new List <ItemData>(), borrados = new List <ItemData>(); Cell pos; switch (canUse(items)) { case 0: { //{"Roca","Roca"} foreach (TWItemScript it in items) { addItemDatatoList(it, borrados); TWItem.destroyItem(it); } pos = (Cell)this.Entity.Position; addItemDatatoList(TWItem.instanceItem("RocaAfilada", pos), pos, nuevos); ge.setParameter("result", "success"); break; } case 1: { //{"Roca","Palo"} foreach (TWItemScript it in items) { addItemDatatoList(it, borrados); TWItem.destroyItem(it); } pos = (Cell)this.Entity.Position; addItemDatatoList(TWItem.instanceItem("Martillo", pos), pos, nuevos); ge.setParameter("result", "success"); break; } case 2: { break; } case 3: { //{"Cantera","Martillo"} bool rotura = Random.Range(0, 10) <= 2; bool piedra = true; //Random.Range(0, 10) <= 6; //bool hierro = Random.Range(0, 10) <= 4; //bool diamante = Random.Range(0, 10) <= 1; Map map = ((Cell)this.Entity.Position).Map; TWItemScript cantera = null; foreach (TWItemScript it in items) { if (it.item.Name == "Cantera") { cantera = it; break; } else if (it.item.Name == "Martillo") { it.Entity.Position = this.Entity.Position; this.GetComponent <Hands>().leftHand = null; this.GetComponent <Hands>().rightHand = null; addItemDatatoList(it, noHanCambiado); } } List <Cell> vecinas = new List <Cell>(map.getNeightbours((Cell)cantera.Entity.Position)); if (rotura) { Decoration dec = cantera.GetComponent <Decoration>(); if (dec.Tile < 2) { dec.Tile = dec.Tile + 1; addItemDatatoList(cantera, noHanCambiado); } else { addItemDatatoList(cantera, borrados); vecinas.Add((Cell)cantera.Entity.Position); TWItem.destroyItem(cantera); } } if (piedra) { pos = vecinas[Random.Range(0, vecinas.Count)]; addItemDatatoList(TWItem.instanceItem("Roca", pos), pos, nuevos); } break; } case 4: { break; } case 5: { //{"Roca Afilada","Palo"} foreach (TWItemScript it in items) { addItemDatatoList(it, borrados); TWItem.destroyItem(it); } pos = (Cell)this.Entity.Position; addItemDatatoList(TWItem.instanceItem("Hacha", pos), pos, nuevos); ge.setParameter("result", "success"); break; } case 6: { break; } case 7: { break; } case 8: { //{"Arbol","Hacha"} int maderas = 1 + Random.Range(0, 3); int palos = 2 + Random.Range(0, 2); //int hojas = 5; int brotes = Random.Range(0, 3); Cell arbol = null; foreach (TWItemScript it in items) { if (it.item.Name == "Arbol") { addItemDatatoList(it, borrados); arbol = (Cell)it.Entity.Position; TWItem.destroyItem(it); } else if (it.item.Name == "Hacha") { it.Entity.Position = this.Entity.Position; this.GetComponent <Hands>().leftHand = null; this.GetComponent <Hands>().rightHand = null; addItemDatatoList(it, noHanCambiado); } } Map map = arbol.Map; Cell[] vecinas = map.getNeightbours(arbol); int dir = Random.Range(0, 4); List <Cell> csbrotes = new List <Cell>(); if (brotes == 1) { if (Random.Range(0, 2) == 0) { csbrotes.Add(vecinas[(dir + 1) % 4]); } else { csbrotes.Add(vecinas[(dir + 3) % 4]); } } else if (brotes == 2) { csbrotes.Add(vecinas[(dir + 1) % 4]); csbrotes.Add(vecinas[(dir + 3) % 4]); } foreach (Cell c in csbrotes) { addItemDatatoList(TWItem.instanceItem("Brote", c), c, nuevos); } for (int i = 1; i <= maderas; i++) { Cell cs = arbol; addItemDatatoList(TWItem.instanceItem("Madera", cs), cs, nuevos); if (i == maderas) { List <Cell> cspalos = new List <Cell>(); cspalos.Add(vecinas[(dir + 1) % 4]); cspalos.Add(vecinas[(dir + 3) % 4]); if (palos > 2) { cspalos.Add(map.getNeightbours(vecinas[(dir + 1) % 4])[(dir + 1) % 4]); } foreach (Cell c in cspalos) { addItemDatatoList(TWItem.instanceItem("Palo", c), c, nuevos); } List <Cell> cshojas = new List <Cell>(); cshojas.Add(vecinas[dir]); Cell[] vecinashojas = map.getNeightbours(vecinas[dir]); cshojas.Add(vecinashojas[dir]); cshojas.Add(vecinashojas[(dir + 1) % 4]); cshojas.Add(vecinashojas[(dir + 3) % 4]); cshojas.Add(map.getNeightbours(vecinashojas[dir])[(dir + 1) % 4]); cshojas.Add(map.getNeightbours(vecinashojas[dir])[(dir + 3) % 4]); foreach (Cell c in cshojas) { addItemDatatoList(TWItem.instanceItem("Hoja", c), c, nuevos); } } arbol = vecinas[dir]; vecinas = map.getNeightbours(vecinas[dir]); } ge.setParameter("result", "success"); break; } case 9: { break; } case 10: { break; } case 11: { addItemDatatoList(items[0], borrados); TWItem.destroyItem(items[0]); pos = (Cell)this.Entity.Position; addItemDatatoList(TWItem.instanceItem("BrotePlantado", pos), pos, nuevos); ge.setParameter("result", "success"); break; } default: { ge.setParameter("result", "cantbeused"); break; } } ge.setParameter("NewItems", nuevos.ToArray()); ge.setParameter("DeletedItems", borrados.ToArray()); ge.setParameter("UnmodifiedItems", noHanCambiado.ToArray()); return(ge); }
public bool canPick(TWItemScript item) { Hands manos = this.GetComponent <Hands>(); return(manos.canPick(item)); }
public override void tick() { while (itemsToPick.Count > 0) { if (itemsToPick[0] != leftHand && itemsToPick[0] != rightHand) { if (itemsToPick[0].item.Manos == 2) { if (rightHand == null && leftHand == null) { rightHand = itemsToPick[0]; leftHand = itemsToPick[0]; itemsToPick[0].GetComponent <Entity>().Position = this.Entity; } } else if (itemsToPick[0].item.Manos == 1) { if (rightHand == null) { rightHand = itemsToPick[0]; itemsToPick[0].GetComponent <Entity>().Position = this.Entity; } else if (leftHand == null) { leftHand = itemsToPick[0]; itemsToPick[0].GetComponent <Entity>().Position = this.Entity; } } } ItemData id = ScriptableObject.CreateInstance <ItemData>(); id.setItem(itemsToPick[0]); events[0].setParameter("item", id); itemsToPick.Remove(itemsToPick[0]); } if (dropLeft) { if (leftHand != null) { Cell[] vecinas = ((Cell)this.Entity.Position).Map.getNeightbours((Cell)this.Entity.Position); foreach (Cell v in vecinas) { if (v.getEntities().Length == 0) { leftHand.Entity.Position = v; if (leftHand == rightHand) { rightHand = null; } leftHand = null; break; } } dropLeft = false; } } if (dropRight) { if (rightHand != null) { Cell[] vecinas = ((Cell)this.Entity.Position).Map.getNeightbours((Cell)this.Entity.Position); foreach (Cell v in vecinas) { if (v != null) { if (v.getEntities().Length == 0) { rightHand.Entity.Position = v; if (leftHand == rightHand) { leftHand = null; } rightHand = null; break; } } } dropRight = false; } } if (drop) { List <Cell> vecinas = new List <Cell>(((Cell)this.Entity.Position).Map.getNeightbours((Cell)this.Entity.Position)); if (vecinas.Contains(dropInto)) { if (leftHand == dropItem) { dropItem.Entity.Position = dropInto; if (leftHand == rightHand) { rightHand = null; } leftHand = null; } else if (rightHand == dropItem) { dropItem.Entity.Position = dropInto; if (leftHand == rightHand) { leftHand = null; } rightHand = null; } } dropItem.Entity.Position = dropInto; drop = false; } while (events.Count > 0) { Game.main.eventFinished(events[0]); events.RemoveAt(0); } }
public override void eventHappened(GameEvent ge) { if (ge.getParameter("minion_id") != null && this.gameObject.GetInstanceID() == ((int)ge.getParameter("minion_id"))) { switch (ge.Name.ToLower()) { case "pick item": Map map = ((Cell)this.Entity.Position).Map; List <Cell> vecinas = new List <Cell> (map.getNeightbours((Cell)this.Entity.Position)); vecinas.Add((Cell)this.Entity.Position); ItemData itd = (ItemData)ge.getParameter("Item"); TWItemScript item = null; if (rightHand != null && rightHand.GetInstanceID() == itd.Id) { item = rightHand; } else if (leftHand != null && leftHand.GetInstanceID() == itd.Id) { item = leftHand; } if (item == null) { foreach (Cell c in vecinas) { List <Entity> entities = new List <Entity> (c.getEntities()); foreach (Entity e in entities) { TWItemScript its = e.GetComponent <TWItemScript> (); if (its != null) { if (its.GetInstanceID() == itd.Id) { item = its; break; } } } if (item == null) { foreach (Entity e in entities) { TWItemScript its = e.GetComponent <TWItemScript> (); if (its != null) { if (its.item.GetInstanceID() == itd.Id) { item = its; break; } } } } if (item != null) { break; } } } if (item != null) { if (leftHand == item || rightHand == item || canPick(item)) { itemsToPick.Add(item); events.Add(ge); } } break; case "drop leftitem": dropLeft = true; events.Add(ge); break; case "drop rightitem": dropRight = true; events.Add(ge); break; case "drop item": drop = true; ItemData tmpItem = (ItemData)ge.getParameter("item"); TWItemScript[] items = GameObject.FindObjectsOfType <TWItemScript> (); foreach (TWItemScript twi in items) { if (twi.GetInstanceID() == tmpItem.Id) { dropItem = twi; break; } } dropInto = ((Cell)this.Entity.Position).Map.fromCoords((Vector2)ge.getParameter("destination")); events.Add(ge); break; } } }