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); } } } }
//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); } } }
private bool hayHueco(TWItem item) { bool hueco = false; switch (item.Manos) { case 1: hueco = leftHand == null || rightHand == null; break; case 2: hueco = leftHand == null && rightHand == null; break; default: hueco = false; break; } return(hueco); }
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); }