public bool Build(List <Worker> workers, Vector2 position, string buildingName) { if (workers.Count == 0) { Debug.Log("Trabalhadores não encontrado!"); return(false); } BuildingDao buildingDao = null; foreach (int buildingId in workers[0].buildings) { if (GameController.gameComponents.buildings[buildingId].name == buildingName) { buildingDao = GameController.gameComponents.buildings[buildingId]; break; } } if (buildingDao == null) { Debug.Log("Building não encontrada!"); return(false); } if (this.player.AddBuilding(map, buildingDao, position)) { player.orders.Add(new BuildOrder(this.player.id, workers, this.player.buildings[Property.nextId])); return(true); } return(false); }
public Player(int id, string name, int populationLimit, bool isHuman = true) { this.id = id; this.name = name; this.isHuman = isHuman; this.script = new Script(this); this.action = new PlayerActions(this); this.scriptAttributes = new ScriptAttributes(); this.propertiesDestroied = new List <Property>(); this.population = 0; this.populationLimit = populationLimit; this.baseMaterials = new Dictionary <int, int>(); this.units = new Dictionary <int, Unit>(); this.buildings = new Dictionary <int, Building> (); this.orders = new List <Order>(); this.standbyOrders = new List <Order>(); this.enemyAttackOrders = new List <AttackOrder>(); this.fog = new Fog(this.id); this.wantBuild = null; }
public List<FullHouse> Query(QueryHouseServiceForm form) { //form.OwnerID = ""; List<FullHouse> list = new List<FullHouse>(); ISqlMapper mapper = MapperHelper.GetMapper(); HouseDao dao = new HouseDao(mapper); House_CustomerDao hcdao = new House_CustomerDao(mapper); CustomerDao customerdao = new CustomerDao(mapper); BuildingDao buildingdao = new BuildingDao(mapper); var house = dao.QueryFullHouse(form); var houseids = (from h in house select h.ID).ToList(); var hos = hcdao.Query(new House_CustomerQueryForm { HouseOrRoomIDs = houseids }); var customerids = (from ho in hos select ho.CustomerID).Distinct().ToList(); var customers = customerdao.Query(new CustomerQueryForm { IDs = customerids, Enabled = 1, IsDeleted = 0 }); var buildingids = (from h in house select h.BuildingID).Distinct().ToList(); var buidlings = buildingdao.Query(new BuildingQueryForm { IDs = buildingids }); foreach (var h in house) { FullHouse fh = new FullHouse { House = h, Customer = (from ho in hos join c in customers on ho.CustomerID equals c.ID where ho.HouseOrRoomID.Equals(h.ID) select c).FirstOrDefault(), Building = buidlings.Find(t => t.ID.Equals(h.BuildingID)), }; list.Add(fh); } return list; }
public string Add(Building building) { building.Enabled = 1; building.IsDeleted = 0; ISqlMapper mapper = MapperHelper.GetMapper(); BuildingDao dao = new BuildingDao(mapper); return dao.Add(building); }
public BuildingEditor(BuildingDao dao) : base() { this.dao = dao; this.projectDao = new ProjectDao(); this.stageDao = new StageDao(); InitializeComponent(); InitData(); }
public OutputUtils() { this.projectDao = new ProjectDao(); this.stageDao = new StageDao(); this.buildingDao = new BuildingDao(); this.floorplanDao = new FloorplanDao(); this.apartmentDao = new ApartmentDao(); this.mediaDao = new MediaDao(); }
public bool Update(Building building) { if (string.IsNullOrEmpty(building.ID)) { throw new Exception("没有楼盘ID"); } ISqlMapper mapper = MapperHelper.GetMapper(); BuildingDao dao = new BuildingDao(mapper); return dao.Update(new BuildingUpdateForm { Entity = building, BuildingQueryForm = new BuildingQueryForm { ID = building.ID } }); }
public bool Delete(string id) { if (string.IsNullOrEmpty(id)) { throw new Exception("没有楼盘ID"); } ISqlMapper mapper = MapperHelper.GetMapper(); BuildingDao dao = new BuildingDao(mapper); return dao.Delete(new BuildingQueryForm { ID = id }); }
void Start() { this.objectName = null; this.buildPlayer = null; this.wantBuild = false; if (GameController.draw) { this.tile = GameObject.Instantiate(Resources.Load("tile_Help", typeof(GameObject)) as GameObject); this.tile.name = "0_tile_0_0_CanBuild"; this.tile.gameObject.SetActive(false); } }
public List<FullHouse> QueryFullHouse(QueryHouseServiceForm form) { List<FullHouse> list = new List<FullHouse>(); ISqlMapper mapper = MapperHelper.GetMapper(); HouseDao dao = new HouseDao(mapper); House_CustomerDao hcdao = new House_CustomerDao(mapper); CustomerDao customerdao = new CustomerDao(mapper); BuildingDao buildingdao = new BuildingDao(mapper); RentFeeDao rfdao = new RentFeeDao(mapper); House_OtherFeeDao hofdao = new House_OtherFeeDao(mapper); OtherFeeDao ofdao = new OtherFeeDao(mapper); var house = dao.QueryFullHouse(form); var houseids = (from h in house select h.ID).ToList(); var hcs = hcdao.Query(new House_CustomerQueryForm { HouseOrRoomIDs = houseids }); var customerids = (from ho in hcs select ho.CustomerID).Distinct().ToList(); var customers = customerdao.Query(new CustomerQueryForm { IDs = customerids, Enabled = 1, IsDeleted = 0, }); var buildingids = (from h in house select h.BuildingID).Distinct().ToList(); var buidlings = buildingdao.Query(new BuildingQueryForm { IDs = buildingids }); var rentfees = rfdao.Query(new RentFeeQueryForm { HouseOrRoomIDs = houseids, Enabled = 1, IsDeleted = 0 }); var rentfeeids = (from rf in rentfees select rf.ID).ToList(); var hos = hofdao.Query(new House_OtherFeeQueryForm { HouseOrRoomIDs = houseids }); var otherfeeids = (from ho in hos select ho.OtherFeeID).Distinct().ToList(); var ofs = ofdao.Query(new OtherFeeQueryForm { IDs = otherfeeids }); foreach (var h in house) { FullHouse fh = new FullHouse { House = h, Customer = (from ho in hcs join c in customers on ho.CustomerID equals c.ID where ho.HouseOrRoomID.Equals(h.ID) && c.Type == (int)CustomerType.业主 select c).FirstOrDefault(), Building = buidlings.Find(t => t.ID.Equals(h.BuildingID)), RentFee = rentfees.Find(t => t.HouseOrRoomID.Equals(h.ID)), OtherFees = (from ho in hos join of in ofs on ho.OtherFeeID equals of.ID where ho.HouseOrRoomID.Equals(h.ID) select of).ToList(), Renter = (from ho in hcs join c in customers on ho.CustomerID equals c.ID where ho.HouseOrRoomID.Equals(h.ID) && c.Type == (int)CustomerType.租客 select c).FirstOrDefault(), }; list.Add(fh); } return list; }
public void CreateGame() { // Tiles TileDao tile_Grass = new TileDao("Grass", "tile_Grass", true, true, 1.0f); TileDao tile_Water = new TileDao("Water", "tile_Water", false, false, 1.0f); TileDao tile_Bridge = new TileDao("Bridge", "tile_Bridge", true, false, 1.0f); // Base Material BaseMaterialDao baseMaterialGold = new BaseMaterialDao("Gold", "Images/material_Gold"); BaseMaterialDao baseMaterialMeat = new BaseMaterialDao("Meat", "Images/material_Meat"); // Material Source MaterialSourceDao mats_Gold = new MaterialSourceDao("Gold", "mats_Gold", 999999999999999999, baseMaterialGold); // Map Component MapComponentDao mc_Tree = new MapComponentDao("Tree", "mc_Tree"); // Buildings BuildingDao build_base = new BuildingDao("Base", "Images/build_Base", "build_Base", new Vector2(2.0f, 2.0f), 3000.0f, 0.0f, true, 3); BuildingDao build_quarter = new BuildingDao("Quarter", "Images/build_Quarter", "build_Quarter", new Vector2(1.0f, 1.0f), 1200.0f, 50.0f, false, 1); build_quarter.cost.Add(baseMaterialGold.id, 200); BuildingDao build_farm = new BuildingDao("Farm", "Images/material_Meat", "build_Farm", new Vector2(1.0f, 1.0f), 500.0f, 30.0f, false, 1, baseMaterialMeat, 1); build_farm.cost.Add(baseMaterialGold.id, 75); BuildingDao build_mine = new BuildingDao("Mine", "Images/build_Mine", "build_Mine", new Vector2(1.0f, 1.0f), 500.0f, 30.0f, false, 1, baseMaterialGold, 1); build_mine.cost.Add(baseMaterialMeat.id, 100); build_mine.requireds.Add(mats_Gold.name); // Warrior Unit CombatDao infantry_unit = new CombatDao("Infantry", "Images/unit_Warrior", "unit_Warrior", 3.0f, 0.0f, 1.0f, 50.0f, 1.0f, 1.0f, new CombatType(), 22.0f, 2); infantry_unit.cost.Add(baseMaterialMeat.id, 35); infantry_unit.cost.Add(baseMaterialGold.id, 25); // Archer Unit CombatDao archer_unit = new CombatDao("Archer", "Images/unit_Archer", "unit_Archer", 4.0f, 0.0f, 0.9f, 30.0f, 4.0f, 1.0f, new CombatType(), 30.0f, 2); archer_unit.cost.Add(baseMaterialMeat.id, 25); archer_unit.cost.Add(baseMaterialGold.id, 45); // Archer Unit CombatDao cavalry_unit = new CombatDao("Cavalry", "Images/unit_Knight", "unit_Knight", 10.0f, 0.0f, 1.5f, 100.0f, 1.0f, 1.0f, new CombatType(), 35.0f, 2); cavalry_unit.cost.Add(baseMaterialMeat.id, 60); cavalry_unit.cost.Add(baseMaterialGold.id, 75); // Worker Unit WorkerDao unit_worker = new WorkerDao("Worker", "Images/unit_Worker", "unit_Worker", 1.0f, 0.0f, 1.0f, 45.0f, 5, 1.0f, 1.0f, 1.0f, 10.0f, 2); unit_worker.cost.Add(baseMaterialMeat.id, 10); unit_worker.buildings.Add(build_quarter.id); unit_worker.buildings.Add(build_farm.id); unit_worker.buildings.Add(build_mine.id); // Add in tiles list tiles.Add(tile_Grass.id, tile_Grass); tiles.Add(tile_Water.id, tile_Water); tiles.Add(tile_Bridge.id, tile_Bridge); // Add in baseMaterial list baseMaterials.Add(baseMaterialGold.id, baseMaterialGold); baseMaterials.Add(baseMaterialMeat.id, baseMaterialMeat); // Add in materialSource list mapComponents.Add(mats_Gold.id, mats_Gold); mapComponents.Add(mc_Tree.id, mc_Tree); // Add in buildings list buildings.Add(build_base.id, build_base); buildings.Add(build_quarter.id, build_quarter); buildings.Add(build_farm.id, build_farm); buildings.Add(build_mine.id, build_mine); // Add in unit list units.Add(infantry_unit.id, infantry_unit); units.Add(archer_unit.id, archer_unit); units.Add(cavalry_unit.id, cavalry_unit); units.Add(unit_worker.id, unit_worker); // Add in unit list of build_base build_base.units.Add(unit_worker.id); build_quarter.units.Add(infantry_unit.id); build_quarter.units.Add(archer_unit.id); build_quarter.units.Add(cavalry_unit.id); SaveGame(); }
public bool AddBuilding(Map map, BuildingDao buildingDao, Vector2 position) { if (position.x > 0 && position.x < (map.width - 1) && position.y > 0 && position.y < (map.height - 1)) { int pos; int i = (int)position.y; int j = (int)position.x; if (!buildingDao.constructed && this.fog.tiles[i, j].unknown) { return(false); } if (buildingDao.requireds.Count > 0) { int requiredNumber = 0; foreach (string required in buildingDao.requireds) { if (map.tiles[i, j].mapComponent != null) { if (map.tiles[i, j].mapComponent.GetType() == typeof(MaterialSource)) { MaterialSource ms = (MaterialSource)map.tiles[i, j].mapComponent; if (!ms.canBuild) { return(false); } } if (map.tiles[i, j].mapComponent.name.CompareTo(required) == 0) { requiredNumber++; } } } if (requiredNumber != buildingDao.requireds.Count) { return(false); } } else { // Check CanBuild Vertically for (pos = 0; pos < buildingDao.size.y; pos++) { if (!map.tiles[(i + pos), j].canBuild) { return(false); } } // Check CanBuild Horizontally for (pos = 0; pos < buildingDao.size.y; pos++) { if (!map.tiles[i, (j + pos)].canBuild) { return(false); } } int wSize = Mathf.Abs((int)buildingDao.size.x) + 2; int hSize = Mathf.Abs((int)buildingDao.size.y) + 2; // Check IsWalkable Vertically for (pos = 0; pos < hSize; pos++) { if (!map.tiles[(pos + i - 1), (j - 1)].isWalkable || !map.tiles[(pos + i - 1), (j + (int)buildingDao.size.x)].isWalkable) { return(false); } } // Check IsWalkable Horizontally for (pos = 0; pos < wSize; pos++) { if (!map.tiles[(i - 1), (pos + j - 1)].isWalkable || !map.tiles[(i + (int)buildingDao.size.y), (pos + j - 1)].isWalkable) { return(false); } } } if (CheckCosts(buildingDao.cost)) { DiscountCosts(buildingDao.cost); Building building = buildingDao.Instantiate(); building.idPlayer = this.id; building.position = position; building.creationPoint = new Vector2(position.x - 1.0f, position.y - 1.0f); this.buildings.Add(building.id, building); building.ModifyTiles(); building.RemoveFog(); if (building.constructed) { building.life = building.lifeTotal; } building.Draw(); return(true); } } return(false); }
public List<FullHouse> QueryFullHouse(QueryHouseServiceForm form) { List<FullHouse> list = new List<FullHouse>(); ISqlMapper mapper = MapperHelper.GetMapper(); UserBLL userbll = new UserBLL(); HouseDao dao = new HouseDao(mapper); House_CustomerDao hcdao = new House_CustomerDao(mapper); CustomerDao customerdao = new CustomerDao(mapper); BuildingDao buildingdao = new BuildingDao(mapper); FollowupDao followupdao = new FollowupDao(mapper); form.IsDeleted = 0; var house = dao.QueryFullHouse(form); var houseids = (from h in house select h.ID).ToList(); var hos = hcdao.Query(new House_CustomerQueryForm { HouseOrRoomIDs = houseids }); var customerids = (from ho in hos select ho.CustomerID).Distinct().ToList(); var customers = customerdao.Query(new CustomerQueryForm { IDs = customerids, Enabled = 1, IsDeleted = 0 }); var buildingids = (from h in house select h.BuildingID).Distinct().ToList(); var buidlings = buildingdao.Query(new BuildingQueryForm { IDs = buildingids }); //var ownerids = (from h in house where !string.IsNullOrEmpty(h.OwnerID.Trim()) select h.OwnerID).Distinct().ToList(); var users = userbll.Query(new FullUserQueryForm { Enabled = 1, IsDeleted = 0 }); var followups = followupdao.Query(new FollowupQueryForm { HouseIDs = houseids }); var fullfollowup = (from f in followups join u in users on f.Creator equals u.ID select new FullFollowup { ID = f.ID, Creator = f.Creator, CreateTime = f.CreateTime, HouseID = f.HouseID, Name = f.Name, CreatorName = u.CnName, Remark = f.Remark }).ToList(); //var rentfee = rentfeebll.Query(new RentFeeQueryForm { HouseOrRoomIDs = houseids, Type = (int)HouseOrRoomType.House, Enabled = 1, IsDeleted = 0 }); //var house_otherfee = hobll.Query(new House_OtherFeeQueryForm { HouseOrRoomIDs = houseids, Type = (int)HouseOrRoomType.House }); //var otherfee = ofbll.Query(new OtherFeeQueryForm { Enabled = 1, IsDeleted = 0 }); foreach (var h in house) { FullHouse fh = new FullHouse { House = h, //RentFee = rentfee.Find(t => t.HouseOrRoomID.Equals(h.ID)), //OtherFees = (from ho in house_otherfeeu //join of in otherfee on ho.OtherFeeID equals of.ID //where ho.HouseOrRoomID.Equals(h.ID) //select of).ToList(), Customer = (from ho in hos join c in customers on ho.CustomerID equals c.ID where ho.HouseOrRoomID.Equals(h.ID) select c).FirstOrDefault(), Building = buidlings.Find(t => t.ID.Equals(h.BuildingID)), Owner = users.Find(t => t.ID.Equals(h.OwnerID)), Followups = fullfollowup.FindAll(t => t.HouseID.Equals(h.ID)), }; //rentfee.Remove(fh.RentFee); //house_otherfee.RemoveAll(t => t.HouseOrRoomID.Equals(fh.House.ID)); list.Add(fh); } return list; }
void Update() { if (GameController.draw) { if (wantBuild) { for (int i = 0; i < 2; i++) { if (GameController.players[i].wantBuild != null) { buildIdPlayer = i; buildPlayer = GameController.players[i].wantBuild; break; } } } if (Input.GetMouseButtonDown(0) && Input.mousePosition.y > 200) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (!GameController.instance.GetComponent <GameController>().isActionButton) { objectName = null; if (Physics.Raycast(ray, out hit, 200.0f)) { objectName = hit.transform.name; } if (tile.gameObject.activeSelf) { wantBuild = false; // Se posição válida if (tile.GetComponent <MeshRenderer>().sharedMaterial.color == Color.green) { if (buildPlayer != null) { Player player = GameController.players[buildIdPlayer]; if (player.AddBuilding(GameController.map, buildPlayer, new Vector2(canBuildColumn, canBuildLine))) { Building buildInstance = player.buildings[Property.nextId]; List <Worker> workers = new List <Worker>(); foreach (Unit unit in GameController.instance.GetComponent <GameController>().selectedUnits) { workers.Add((Worker)unit); } Debug.Log("Add BuildOrder"); player.orders.Add(new BuildOrder(player.id, workers, buildInstance)); /** * foreach(Worker worker in GameController.instance.GetComponent<GameController>().selectedUnits) { * worker.targetBuilding = buildInstance; * worker.isWalking = false; * } * /**/ GameController.instance.GetComponent <GameController>().LeftClick(GameController.instance.GetComponent <GameController>().selectedUnits[0].model.name, hit.transform.position); GameController.instance.GetComponent <GameController>().DrawInfoMaterials(); } buildPlayer = null; } tile.gameObject.SetActive(false); } else { tile.gameObject.SetActive(false); } } else { wantBuild = false; tile.gameObject.SetActive(false); if (hit.transform != null) { GameController.instance.GetComponent <GameController>().LeftClick(objectName, hit.transform.position); } } } else { if (Physics.Raycast(ray, out hit, 200.0f) && objectName != null) { GameController.instance.GetComponent <GameController>().RightClick(objectName, hit.transform.name, hit.transform.position.x, hit.transform.position.z); } GameController.instance.GetComponent <GameController> ().isActionButton = false; } } if (wantBuild) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 200.0f)) { string[] variables = hit.collider.name.Split('_'); if (variables [1].CompareTo("tile") == 0 || variables [1].CompareTo("source") == 0) { Map map = GameController.map; float xIni = (float)map.GetTileSize() * (map.width - 1) / -2; float yIni = (float)map.GetTileSize() * (map.height - 1) / 2; //Debug.Log("("+yIni+", "+xIni+")"); /** * float xAdd = 0.0f, zAdd = 0.0f; * * if (xIni - Mathf.CeilToInt (xIni) > 0) { * xAdd = 0.5f; * } else if (xIni - Mathf.CeilToInt (xIni) < 0) { * xAdd = -0.5f; * } * * if (yIni - Mathf.CeilToInt (yIni) > 0) { * zAdd = 0.5f; * } else if (yIni - Mathf.CeilToInt (yIni) < 0) { * zAdd = -0.5f; * } * /**/ int line = (map.height / 2) - Mathf.CeilToInt(hit.point.z); int column = Mathf.CeilToInt(hit.point.x) + (map.width / 2) - 1; if (buildPlayer.requireds.Count > 0 && line > 0 && line < map.height && column > 0 && column < map.width) { int requiredNumber = 0; foreach (string required in buildPlayer.requireds) { if (map.tiles[line, column].mapComponent != null && map.tiles[line, column].mapComponent.name.CompareTo(required) == 0) { requiredNumber++; } } if (requiredNumber == buildPlayer.requireds.Count) { this.canBuildLine = line; this.canBuildColumn = column; tile.GetComponent <MeshRenderer> ().sharedMaterial.color = Color.green; } else { tile.GetComponent <MeshRenderer> ().sharedMaterial.color = Color.red; } } else if (map.tiles [line, column].canBuild && line > 0 && line < (map.height - 1) && column > 0 && column < (map.width - 1)) { this.canBuildLine = line; this.canBuildColumn = column; tile.GetComponent <MeshRenderer> ().sharedMaterial.color = Color.green; } else { tile.GetComponent <MeshRenderer> ().sharedMaterial.color = Color.red; } /** * for (int i = 0; i < map.height; i++) { * for (int j = 0; j < map.width; j++) { * * if (map.tiles [i, j].model.transform.position.x == (Mathf.CeilToInt (hit.point.x) + xAdd) && * map.tiles [i, j].model.transform.position.z == (Mathf.CeilToInt (hit.point.z - 0.5f) + zAdd)) { * * if (i > 0 && i < (map.height - 1) && j > 0 && j < (map.width - 1)) { * * if (buildPlayer.requireds.Count > 0) { * * int requiredNumber = 0; * * foreach (string required in buildPlayer.requireds) { * * if (map.tiles [i, j].mapComponent != null) { * * if (map.tiles [i, j].mapComponent.name.CompareTo (required) == 0) { * requiredNumber++; * } * * } * * } * * if (requiredNumber == buildPlayer.requireds.Count) { * this.canBuildLine = i; * this.canBuildColumn = j; * tile.GetComponent<MeshRenderer> ().sharedMaterial.color = Color.green; * } else { * tile.GetComponent<MeshRenderer> ().sharedMaterial.color = Color.red; * } * * } else if (map.tiles [i, j].canBuild) { * * this.canBuildLine = i; * this.canBuildColumn = j; * tile.GetComponent<MeshRenderer> ().sharedMaterial.color = Color.green; * * } else { * tile.GetComponent<MeshRenderer> ().sharedMaterial.color = Color.red; * } * } else { * * tile.GetComponent<MeshRenderer> ().sharedMaterial.color = Color.red; * * } * * break; * } else { * tile.gameObject.SetActive (false); * } * * } * }*/ tile.gameObject.SetActive(true); tile.transform.position = new Vector3(xIni + column, 0.0f, yIni - line); } else { tile.gameObject.SetActive(false); } } } } }
public List<Building> Query(BuildingQueryForm form) { ISqlMapper mapper = MapperHelper.GetMapper(); BuildingDao dao = new BuildingDao(mapper); return dao.Query(form); }