public void Generate(object state) { S2CChickenLoc s2CChickenLoc = new S2CChickenLoc() { chickenLocList = new List <ChickenLoc>() }; GameMap gameMap = GameMapManager.instance.GetGameMap(0); GenerateItem.GenerateChicken(gameMap, 36, 36, ref s2CChickenLoc); SendChickenLoc(s2CChickenLoc); }
public static void GenerateChicken(GameMap map, int width, int hight, ref S2CChickenLoc s2CChickenLoc) { int mid = width / 2; int chickenCount = 0; for (int i = 0; i < width; i++) { for (int j = 0; j < hight; j++) { if (map.gameMap[i, j] == 0) { int[] mapXZ = new int[2]; mapXZ[0] = i; mapXZ[1] = j; ReadConfig.instance.mapRandomChicken.Add(mapXZ); } } } while (true) { if (chickenCount >= 4) { break; } ChickenLoc chickenLoc = new ChickenLoc(); int mapRandomIndex = random.Next(0, ReadConfig.instance.mapRandomChicken.Count); var x = ReadConfig.instance.mapRandomChicken[mapRandomIndex][0]; var z = ReadConfig.instance.mapRandomChicken[mapRandomIndex][1]; if (x < mid && x - ReadConfig.instance.canChickenDis < 0) { if (z < mid && z - ReadConfig.instance.canChickenDis < 0) { setMapvalue(map, x, z, mapRandomIndex); chickenLoc.x = x; chickenLoc.z = z; s2CChickenLoc.chickenLocList.Add(chickenLoc); chickenCount++; } else if (z >= mid && z + ReadConfig.instance.canChickenDis >= hight) { setMapvalue(map, x, z, mapRandomIndex); chickenLoc.x = x; chickenLoc.z = z; s2CChickenLoc.chickenLocList.Add(chickenLoc); chickenCount++; } } else if (x >= mid && x + ReadConfig.instance.canChickenDis >= width) { if (z < mid && z - ReadConfig.instance.canChickenDis < 0) { setMapvalue(map, x, z, mapRandomIndex); chickenLoc.x = x; chickenLoc.z = z; s2CChickenLoc.chickenLocList.Add(chickenLoc); chickenCount++; } else if (z >= mid && z + ReadConfig.instance.canChickenDis >= hight) { setMapvalue(map, x, z, mapRandomIndex); chickenLoc.x = x; chickenLoc.z = z; s2CChickenLoc.chickenLocList.Add(chickenLoc); chickenCount++; } } } }
public void SendChickenLoc(S2CChickenLoc s2CChickenLoc) { SendData.instance.Broadcast((int)messageType.S2CChickenLoc, s2CChickenLoc); }