/// <summary> /// Instantiate Residence Node, with the given parameters. If no TiledArea is specified, a new TiledArea is created and added to the region. Default rotation is identity. See overload including rotation /// </summary> /// <typeparam name="T"></typeparam> /// <param name="residencePrefab"></param> /// <param name="position"></param> /// <param name="rotation"></param> /// <param name="parentTiledArea"></param> /// <param name="residenceName"></param> /// <returns></returns> public T CreateResidence <T>(GameObject residencePrefab, Vector3 position, Quaternion rotation, TiledArea parentTiledArea = null, string residenceName = "defaultResidence") where T : MonoBehaviour, INode, IResidence, IArea { GameObject newResidence = Instantiate(residencePrefab, position, rotation); UtilityFunctions.PutObjectOnGround(newResidence.transform); T residenceNode = newResidence.AddComponent <T>(); residenceNode.SetUp(residenceName); residenceNode.transform.parent = transform; residenceNode.SetUpResidence(this, new List <INode>()); // TODO: Generalise hut dimensions using data of the hut prefab itself residenceNode.SetUpArea(residenceNode.transform, hutDimensions); AddLink(residenceNode); Residences.Add(residenceNode); Areas.Add(residenceNode); VillageData.SetHutCount(VillageData.HutCount + 1); // If tiled area was not provided, then create a new one if (parentTiledArea is null) { var newTiledArea = new TiledArea(residenceNode); TiledAreas.Add(newTiledArea); } else { parentTiledArea.AddArea(residenceNode); } return(residenceNode); }
public void HandleEventItem(EventItem item) { switch (item.Type) { case EEventItemType.LoginSuccess: VillageData.DB_QueryPlayerVillageData(); break; case EEventItemType.PlayerVillageDataLoaded: PlayerVillageData = LastGetVillageData; PlayerVillageData.BuildingDic = new Dictionary <int, BuildingData>(); foreach (BuildingData buildingData in LastGetBuildingDataList) { PlayerVillageData.BuildingDic.Add(buildingData.SlotID, buildingData); } PlayerBuildingDataList = LastGetBuildingDataList; VillageComp.SetVillageTo(AVUser.CurrentUser, PlayerVillageData, PlayerBuildingDataList); UIManager.Instance.ChangeScreen(EScreen.Build); break; case EEventItemType.BuildCommandOK: PlayerVillageData.AddNewBuilding(LastCreatedBuilding); VillageComp.BuildingGroupComp.AddNewBuilding(LastCreatedBuilding); break; case EEventItemType.MatchFound: UIManager.Instance.UISearchPanel.SetMatch(LastMatchUser, LastMathVillage); break; case EEventItemType.EnemyBuildingLoaded: StartFight(); break; } }
public static void DB_QueryPlayerVillageData() { AVQuery<AVObject> query=new AVQuery<AVObject>("Village").WhereEqualTo("UserID", AVUser.CurrentUser.ObjectId); query.FirstAsync().ContinueWith(t =>{ AVObject villageObject = (t as Task<AVObject>).Result; VillageData villageData = new VillageData(); villageData.UserID = villageObject.Get<string>("UserID"); villageData.Defence = villageObject.Get<int>("Defence"); villageData.Power = villageObject.Get<int>("Power"); villageData.Trick = villageObject.Get<int>("Trick"); villageData.Belief = villageObject.Get<int>("Belief"); villageData.BeliefAll = villageObject.Get<int>("BeliefAll"); GameManager.Instance.LastGetVillageData = villageData; Debug.LogWarning(villageData.UserID); AVQuery<AVObject> buildingQuery = new AVQuery<AVObject>("Building").WhereEqualTo("UserID", AVUser.CurrentUser.ObjectId); buildingQuery.FindAsync().ContinueWith(t2=>{ List<BuildingData> buildingDataList = new List<BuildingData>(); foreach(AVObject buildingObject in (t2 as Task<IEnumerable<AVObject>>).Result) { BuildingData buildingData = new BuildingData(); buildingData.UserID = buildingObject.Get<string>("UserID"); buildingData.Type = (EBuildingType)buildingObject.Get<int>("Type"); buildingData.Level = buildingObject.Get<int>("Level"); buildingData.Value = buildingObject.Get<int>("Value"); buildingData.SlotID = buildingObject.Get<int>("SlotID"); buildingDataList.Add(buildingData); } GameManager.Instance.LastGetBuildingDataList = buildingDataList; GameManager.Instance.EventQueue.Queue.Enqueue(new EventItem(){Type = EEventItemType.PlayerVillageDataLoaded}); }); }); }
/// <summary> /// Function should be called upon creation. Sets up internal parameters, and then spawns the villagers and huts /// </summary> /// <param name="prefab"></param> public void SetUpVillage(VillageData villageData) { Residences = new HashSet <IResidence>(); Areas = new HashSet <IArea>(); VillageData = villageData; }
public void StartFight() { UIManager.Instance.ChangeScreen(EScreen.Fight); VillageComp.SetVillageTo(LastMatchUser, VillageData.CreateFromAVObject(LastMathVillage), LastMatchBuildingDataList); IsFighting = true; HitCount = 0; VillageComp.EnemyGroupComp.EnemyComp.Restart(); }
public static Village Load(VillageData data, Player p) { var v = new Village(p, new Guid(data.id)); v.setCityWalls(data.cityWall); v.setVillageType(data.myKind); return(v); }
public static VillageData CreateFromAVObject(AVObject obj) { VillageData villageData = new VillageData(); villageData.UserID = obj.Get<string>("UserID"); villageData.Defence = obj.Get<int>("Defence"); villageData.Power = obj.Get<int>("Power"); villageData.Trick = obj.Get<int>("Trick"); villageData.Belief = obj.Get<int>("Belief"); villageData.BeliefAll = obj.Get<int>("BeliefAll"); return villageData; }
public void SetVillageTo(AVUser user, VillageData villageData, List<BuildingData> buildingDataList) { CurUser = user; CurVillageData = villageData; CurBuildingDataList = buildingDataList; if(user != AVUser.CurrentUser) IsPlayerVillage = false; BuildingGroupComp.ReloadAllBuildings(buildingDataList); }
public static void SaveVillage(GlobalVariables villageSaver) { BinaryFormatter bf = new BinaryFormatter(); //Directory.CreateDirectory("/eggSaver"); FileStream stream = new FileStream(Application.persistentDataPath + "/villageSaver.sav", FileMode.Create); VillageData data = new VillageData(villageSaver); bf.Serialize(stream, data); stream.Close(); }
public static VillageData CreateFromAVObject(AVObject obj) { VillageData villageData = new VillageData(); villageData.UserID = obj.Get <string>("UserID"); villageData.Defence = obj.Get <int>("Defence"); villageData.Power = obj.Get <int>("Power"); villageData.Trick = obj.Get <int>("Trick"); villageData.Belief = obj.Get <int>("Belief"); villageData.BeliefAll = obj.Get <int>("BeliefAll"); return(villageData); }
public void SetVillageTo(AVUser user, VillageData villageData, List <BuildingData> buildingDataList) { CurUser = user; CurVillageData = villageData; CurBuildingDataList = buildingDataList; if (user != AVUser.CurrentUser) { IsPlayerVillage = false; } BuildingGroupComp.ReloadAllBuildings(buildingDataList); }
public void DoRegist(string userName, string password, string email) { AVUser user = new AVUser(); user.Username = userName; user.Password = password; user.Email = email; user.SignUpAsync().ContinueWith(t => { UID = user.ObjectId; // 创建玩家的Village VillageData.DB_CreateVillage(); }); }
/// <summary> /// Instantiates a new object and assigns a VillageNode to that object. Sets up that VillageNode with parameters according to villageData. /// </summary> /// <param name="centerPosition"></param> /// <param name="spawnRadius"></param> /// <param name="name"></param> /// <returns></returns> private VillageNode CreateVillageNode(Vector3 centerPosition, VillageData villageData, string name = "Default Village") { var spawnRadius = villageData.maxRadius; string newVillageName = name; // Initialize new Village Center GameObject newVillageObject = new GameObject(name: newVillageName); var newVillageNode = newVillageObject.AddComponent <VillageNode>(); newVillageNode.SetUp(newVillageName); newVillageNode.SetUpRegion(spawnRadius, centerPosition); // Initializing Village for generation newVillageNode.SetUpVillage(villageData); return(newVillageNode); }
/// <summary> /// Generates a random instance of Village Data from the specified generator data. /// </summary> /// <param name="generatorData"></param> /// <returns></returns> private VillageData GenerateVillageData(VillageGeneratorData generatorData, float maxRadius) { var newVillageData = new VillageData { HeadCount = villageGeneratorData.headCount.RandomSample(), hutSpawnRange = generatorData.percentageHutSpawnRadius * (maxRadius / 100), elderHutSpawnRange = generatorData.percentageElderHutSpawnRadius * (maxRadius / 100), maxRadius = maxRadius, villagersPerHut = generatorData.villagersPerHut, villagerPrefab = generatorData.villagerPrefab, elderHutPrefab = generatorData.elderHutPrefab, hutPrefab = generatorData.hutPrefab }; return(newVillageData); }
private void GenerateWorldData() { int numberVillages = 5; int numberDungeons = 10; //Generate VillageLocations for (int i = 0; i < numberVillages; i++) { VillageData d = new VillageData(); d.Loc = GenerateVillageChunkLocation(); wData.Villages.Add(d); } //Connect each village to a random village for (int j = 0; j < wData.Villages.Count; j++) { wData.Villages[j].ConnectedVillageLoc = wData.Villages[Game.rng.Next(wData.Villages.Count)].Loc; wData.Villages[j].VillageToVillage = new Ray(wData.Villages[j].Loc, wData.Villages[j].ConnectedVillageLoc); for (int x = 0; x < wData.worldSize; x++) { for (int y = 0; y < wData.worldSize; y++) { Rectangle chunkRect = new Rectangle(x * wData.chunkSize, y * wData.chunkSize, wData.chunkSize, wData.chunkSize); if (Ray.isIntersectingRect(wData.Villages[j].VillageToVillage, chunkRect)) { if (wData.Villages[j].roadChunks == null) { wData.Villages[j].roadChunks = new List <Point>(); } wData.Villages[j].roadChunks.Add(new Point(x, y)); } } } } for (int k = 0; k < numberDungeons; k++) { DungeonData d = new DungeonData(); d.DoorChunkLoc = GenerateDungeonLocation(); d.DoorLoc = new Point(d.DoorChunkLoc.X % 100, d.DoorChunkLoc.Y % 100); d.seed = Game.rng.Next(); wData.Dungeons.Add(d); } }
public static List <bool> LoadDissolvedSeasons() { if (File.Exists(Application.persistentDataPath + "/villageSaver.sav")) { BinaryFormatter bf = new BinaryFormatter(); FileStream stream = new FileStream(Application.persistentDataPath + "/villageSaver.sav", FileMode.Open); VillageData data = bf.Deserialize(stream) as VillageData; stream.Close(); return(data.dissolvedSeasons); } else { Debug.LogWarning("FILE DOES NOT EXIST"); return(new List <bool>()); } }
public void Load() { if (File.Exists(Application.persistentDataPath + "/playerInfo.dat") && File.Exists(Application.persistentDataPath + "/openWorldInfo.dat")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/playerInfo.dat", FileMode.Open); playerData = (PlayerData)bf.Deserialize(file); file.Close(); file = File.Open(Application.persistentDataPath + "/openWorldInfo.dat", FileMode.Open); openWorldData = (OpenWorldData)bf.Deserialize(file); file.Close(); file = File.Open(Application.persistentDataPath + "/villageInfo.dat", FileMode.Open); villageData = (VillageData)bf.Deserialize(file); file.Close(); } }
/// <summary> /// Extracts villages. /// </summary> /// <param name="content">Content to extract.</param> /// <returns>Extracted village data.</returns> public static VillageData[] Villages(string content) { string ownerName = GetMatch(content, "v owner name") .Groups["name"].Value; var mc = GetMatches(content, "v*"); var data = new VillageData[mc.Count]; for (int i = 0; i < mc.Count; i++) { var id = mc[i].Groups["id"].Value.AsInt(); var name = mc[i].Groups["name"].Value; var pop = mc[i].Groups["pop"].Value.AsInt(); bool central = mc[i].Groups["central"].Success; data[i++] = new VillageData(id, name, pop, ownerName, central); } return(data); }
private void AddGroup(string group, VillageData villageData) { var groupData = GetGroupByVillage(villageData); if (groupData != null) { if (!groupData.Names.Exists(x => x.Equals(group))) { _groupDataCoord[new Tuple <int, int>(villageData.X, villageData.Y)].Names.Add(group); } } else { groupData = new GroupData( ) { Village = villageData }; groupData.Names.Add(group); _groupDataCoord.Add(new Tuple <int, int>(villageData.X, villageData.Y), groupData); } }
/// <summary> /// Decide how many huts are required in the traditional generation sequence. /// </summary> /// <param name="villageData"></param> /// <returns></returns> private int DecideNumberOfHuts(VillageData villageData) { int headCount = villageData.HeadCount; // At the minimum, if each hut is maximally cramped, what is the number of huts needed? int minHutsNeeded = Mathf.CeilToInt((float)headCount / villageData.villagersPerHut.max); // If min villagers per hut is 0, then huts can be left empty. Thus there is no maximum capacity configuration if (villageData.villagersPerHut.min > 0) { // If a cap exists (that is, the number of huts cannot exceed a quantity) int maxHutsNeeded = Mathf.CeilToInt((float)headCount / villageData.villagersPerHut.min); // Return a random value between min and max return(Random.Range(minHutsNeeded, maxHutsNeeded + 1)); } else { // No cap on number of huts // Return a exponentially distributed random value between min case and 1 for each villager case float exponent = Random.Range(0f, 1f); return(Mathf.RoundToInt(minHutsNeeded * Mathf.Pow(headCount / minHutsNeeded, exponent))); } }
public static void DB_QueryPlayerVillageData() { AVQuery <AVObject> query = new AVQuery <AVObject>("Village").WhereEqualTo("UserID", AVUser.CurrentUser.ObjectId); query.FirstAsync().ContinueWith(t => { AVObject villageObject = (t as Task <AVObject>).Result; VillageData villageData = new VillageData(); villageData.UserID = villageObject.Get <string>("UserID"); villageData.Defence = villageObject.Get <int>("Defence"); villageData.Power = villageObject.Get <int>("Power"); villageData.Trick = villageObject.Get <int>("Trick"); villageData.Belief = villageObject.Get <int>("Belief"); villageData.BeliefAll = villageObject.Get <int>("BeliefAll"); GameManager.Instance.LastGetVillageData = villageData; Debug.LogWarning(villageData.UserID); AVQuery <AVObject> buildingQuery = new AVQuery <AVObject>("Building").WhereEqualTo("UserID", AVUser.CurrentUser.ObjectId); buildingQuery.FindAsync().ContinueWith(t2 => { List <BuildingData> buildingDataList = new List <BuildingData>(); foreach (AVObject buildingObject in (t2 as Task <IEnumerable <AVObject> >).Result) { BuildingData buildingData = new BuildingData(); buildingData.UserID = buildingObject.Get <string>("UserID"); buildingData.Type = (EBuildingType)buildingObject.Get <int>("Type"); buildingData.Level = buildingObject.Get <int>("Level"); buildingData.Value = buildingObject.Get <int>("Value"); buildingData.SlotID = buildingObject.Get <int>("SlotID"); buildingDataList.Add(buildingData); } GameManager.Instance.LastGetBuildingDataList = buildingDataList; GameManager.Instance.EventQueue.Queue.Enqueue(new EventItem() { Type = EEventItemType.PlayerVillageDataLoaded }); }); }); }
public static void SellPlot(VillageData villageData) { var scrapItems = new List <(string, int)> { ("tools", 3) }; int sellPrice = villageData.AcreBuyPrice; if (villageData.playerAcres > 0) { villageData.sellAcre(); // Getting back our sweet materials. foreach (var scrap in scrapItems) { ItemObject scrapItem = Items.FindFirst(item => item.StringId.Equals(scrap.Item1)); Hero.MainHero.PartyBelongedTo.ItemRoster.AddToCounts(scrapItem, scrap.Item2); } GiveGoldAction.ApplyForSettlementToCharacter(Settlement.CurrentSettlement, Hero.MainHero, sellPrice); } else { InformationManager.DisplayMessage(new InformationMessage("You have no plots to sell.")); } }
public void TestBattle() { // 初始化假玩家数据 PlayerVillageData = new VillageData(){UserID = "player_user_id", Defence = 0, Power = 0, Trick = 0, Belief = 0}; PlayerBuildingDataList.AddRange(new BuildingData[]{ new BuildingData(){UserID = "player_user_id", Type = EBuildingType.Altar, SlotID = 0, Level = 3, Sibling = 1}, new BuildingData(){UserID = "player_user_id", Type = EBuildingType.Church, SlotID = 1, Level = 3, Sibling = 1}, new BuildingData(){UserID = "player_user_id", Type = EBuildingType.Lib, SlotID = 2, Level = 3, Sibling = 1}, new BuildingData(){UserID = "player_user_id", Type = EBuildingType.Tower, SlotID = 3, Level = 3, Sibling = 1}, }); // 计算玩家属性 RecalcPlayerProperties(); // 初始化假敌人数据 AVUser tempUser = new AVUser(){ObjectId = "enemy_user_id", Username = "******"}; OtherUserData = new UserData(tempUser); OtherVillageData = new VillageData(){UserID = "enemy_user_id", Defence = 0, Power = 0, Trick = 0, Belief = 0}; OtherBuildingDataList = new List<BuildingData>(); OtherBuildingDataList.AddRange(new BuildingData[]{ new BuildingData(){UserID = "enemy_user_id", Type = EBuildingType.Altar, SlotID = 0, Level = 3, Sibling = 1}, new BuildingData(){UserID = "enemy_user_id", Type = EBuildingType.Church, SlotID = 1, Level = 3, Sibling = 1}, new BuildingData(){UserID = "enemy_user_id", Type = EBuildingType.Lib, SlotID = 2, Level = 3, Sibling = 1}, new BuildingData(){UserID = "enemy_user_id", Type = EBuildingType.Tower, SlotID = 3, Level = 3, Sibling = 1}, }); // 计算敌人属性 RecalcPlayerProperties(); // 初始化敌人场景 SceneManager.Instance.SwitchScene(ESceneMode.Battle); // 启动战斗UI UIManager.Instance.ChangeScreen(EScreen.Fight); // 开启战斗状态 SceneManager.Instance.SceneComp_Battle.StartFight(); // -- 此处强切一次状态 SceneManager.Instance.SceneComp_Battle.BattleState = EBattleState.BattleOn; }
// TODO 将测试战斗转换为单机关卡 public void TestBattleInitial() { /* // 初始化假玩家数据 PlayerUserData = new AVUser(){ObjectId = "player_user_id", Username = "******"}; PlayerVillageData = new VillageData(){UserID = "player_user_id", Defence = 0, Power = 0, Trick = 0, Belief = 0}; PlayerBuildingDataList = new List<BuildingData>(); PlayerBuildingDataList.AddRange(new BuildingData[]{ new BuildingData(){UserID = "player_user_id", Type = EBuildingType.Altar, SlotID = 0, Level = 3, Sibling = 1}, new BuildingData(){UserID = "player_user_id", Type = EBuildingType.Church, SlotID = 1, Level = 3, Sibling = 1}, new BuildingData(){UserID = "player_user_id", Type = EBuildingType.Lib, SlotID = 2, Level = 3, Sibling = 1}, new BuildingData(){UserID = "player_user_id", Type = EBuildingType.Tower, SlotID = 3, Level = 3, Sibling = 1}, }); // 计算玩家属性 RecalcAllPlayerProperty(); */ // 初始化假敌人数据 AVUser tempUser = new AVUser(){ObjectId = "enemy_user_id", Username = "******"}; OtherUserData = new UserData(tempUser); OtherVillageData = new VillageData(){UserID = "enemy_user_id", Defence = 0, Power = 0, Trick = 0, Belief = 0}; OtherBuildingDataList = new List<BuildingData>(); OtherBuildingDataList.AddRange(new BuildingData[]{ new BuildingData(){UserID = "enemy_user_id", Type = EBuildingType.Altar, SlotID = 0, Level = 3, Sibling = 1}, new BuildingData(){UserID = "enemy_user_id", Type = EBuildingType.Church, SlotID = 1, Level = 3, Sibling = 1}, new BuildingData(){UserID = "enemy_user_id", Type = EBuildingType.Lib, SlotID = 2, Level = 3, Sibling = 1}, new BuildingData(){UserID = "enemy_user_id", Type = EBuildingType.Tower, SlotID = 3, Level = 3, Sibling = 1}, }); // 计算敌人属性 RecalcPlayerProperties(); // 初始化敌人场景 SceneManager.Instance.SwitchScene(ESceneMode.Visit); }
// 获取特定玩家信息 public void NetGetOtherByID(string objectID, Action callback) { GameManager.Instance.AsyncBeginWait(); var query = new AVQuery<AVObject>("Village").WhereEqualTo("UserID", objectID); query.FindAsync().ContinueWith(t=>{ List<AVObject> objList = new List<AVObject>(); objList.AddRange((t as Task<IEnumerable<AVObject>>).Result); if(objList.Count > 0) { AVObject villageObject = objList[0]; VillageData villageData = new VillageData(); villageData.AVObject = villageObject; AVQuery<AVObject> buildingQuery = new AVQuery<AVObject>("Building").WhereEqualTo("UserID", villageData.UserID); buildingQuery.FindAsync().ContinueWith(t2=>{ List<BuildingData> buildingDataList = new List<BuildingData>(); foreach(AVObject buildingObject in (t2 as Task<IEnumerable<AVObject>>).Result) { BuildingData buildingData = new BuildingData(); buildingData.AVObject = buildingObject; buildingDataList.Add(buildingData); } GameManager.Instance.AsyncEndWait(()=>{ OtherVillageData = villageData; OtherVillageData.BuildingDataList = buildingDataList; if(callback != null) callback(); }); }); } }); }
// 网络-获取随机玩家 public void NetGetRandomOther(Action callback) { GameManager.Instance.AsyncBeginWait(); var query = new AVQuery<AVObject>("Village").WhereNotEqualTo("UserID", AVUser.CurrentUser.ObjectId); Debug.Log("开始查找敌人村落"); query.FindAsync().ContinueWith(t=>{ List<AVObject> objList = new List<AVObject>(); objList.AddRange((t as Task<IEnumerable<AVObject>>).Result); if(objList.Count > 0) { var rand = new System.Random(); int r = rand.Next(objList.Count); AVObject villageObject = objList[r]; VillageData villageData = new VillageData(); villageData.AVObject = villageObject; Debug.Log("开始查找敌人建筑"); AVQuery<AVObject> buildingQuery = new AVQuery<AVObject>("Building").WhereEqualTo("UserID", villageData.UserID); buildingQuery.FindAsync().ContinueWith(t2=>{ List<BuildingData> buildingDataList = new List<BuildingData>(); foreach(AVObject buildingObject in (t2 as Task<IEnumerable<AVObject>>).Result) { BuildingData buildingData = new BuildingData(); buildingData.AVObject = buildingObject; buildingDataList.Add(buildingData); } Debug.Log("找到敌人建筑"); GameManager.Instance.AsyncEndWait(()=>{ OtherVillageData = villageData; OtherVillageData.BuildingDataList = buildingDataList; if(callback != null) callback(); }); }); } }); }
// 网络-获取玩家村落信息 public void NetQueryPlayerVillageData(Action callback = null) { GameManager.Instance.AsyncBeginWait(); AVQuery<AVObject> query=new AVQuery<AVObject>("Village").WhereEqualTo("UserID", AVUser.CurrentUser.ObjectId); query.FirstAsync().ContinueWith(t =>{ AVObject villageObject = (t as Task<AVObject>).Result; VillageData villageData = new VillageData(); villageData.AVObject = villageObject; AVQuery<AVObject> buildingQuery = new AVQuery<AVObject>("Building").WhereEqualTo("UserID", AVUser.CurrentUser.ObjectId); buildingQuery.FindAsync().ContinueWith(t2=>{ List<BuildingData> buildingDataList = new List<BuildingData>(); foreach(AVObject buildingObject in (t2 as Task<IEnumerable<AVObject>>).Result) { BuildingData buildingData = new BuildingData(); buildingData.AVObject = buildingObject; buildingDataList.Add(buildingData); } GameManager.Instance.AsyncEndWait(()=>{ PlayerManager.Instance.PlayerVillageData = villageData; PlayerManager.Instance.PlayerVillageData.BuildingDataList = new List<BuildingData>(); PlayerManager.Instance.PlayerVillageData.BuildingDataList = buildingDataList; if(callback != null) callback(); }); }); }); }
public VillagePropertyMenuViewModel(ref VillageData acreProperties) { this._villageData = acreProperties; }
IEnumerator GenerateVillages(ChunkData chunkData) { float maxVillageDistance = ProceduralTerrain.Current.TerrainHouseData.MaxDistanceOfVillage; int minHousesPerVillage = ProceduralTerrain.Current.TerrainHouseData.MaxHousesPerVillage; int maxHousesPerVillage = ProceduralTerrain.Current.TerrainHouseData.MinHousesPerVillage; //List to store individual villages List <VillageData> villageList = new List <VillageData>(); //List to store objects that need deleting List <VillageData> villagesToDelete = new List <VillageData>(); //Go through house, check through all other houses, if within maxVillageDistance, add them to village foreach (VillageHouseData house1 in chunkData.VillageHouseList) { //If already has a village, move to next house if (house1.Village != null) { continue; } foreach (VillageHouseData house2 in chunkData.VillageHouseList) { //Make sure not comparing to self if (house1 == house2) { continue; } //House2 should not already have a village if (house2.Village != null) { continue; } //If house1 doesnt have a village, create one if (house1.Village == null) { VillageData thisVillage = new VillageData(); thisVillage.AddHouse(house1); villageList.Add(thisVillage); } //If distance been house1 and house2 is less than the max village distance if (Vector3.Distance(house1.transform.position, house2.transform.position) < maxVillageDistance) { //Assign house2 to village house1.Village.AddHouse(house2); } } } //Assign village list to chunk chunkData.VillageList = villageList; //If village has less than required houses, delete it foreach (VillageData village in chunkData.VillageList) { if (village.VillageSize < minHousesPerVillage) { villagesToDelete.Add(village); } } for (int i = 0; i < villagesToDelete.Count; i++) { villageList.Remove(villagesToDelete[i]); villagesToDelete[i].DestroyVillage(); } villagesToDelete.Clear(); //Get middle point of villages Vector3 center = Vector3.zero; foreach (VillageData village in chunkData.VillageList) { foreach (VillageHouseData house in village.VillageHouses) { center += house.transform.position; } //Find average of all house positions center /= village.VillageSize; village.CenterPosition = center; } //If village has more than max number of houses, reduce amount of houses by removing the houses furthest from the center foreach (VillageData village in chunkData.VillageList) { //Keep removing houses until there is less than the max amount while (village.VillageSize > maxHousesPerVillage) { VillageHouseData furthestHouse = village.VillageHouses[0]; float furthestDistance = float.MinValue; foreach (VillageHouseData house in village.VillageHouses) { if (Vector3.Distance(house.transform.position, village.CenterPosition) > furthestDistance) { furthestDistance = Vector3.Distance(house.transform.position, village.CenterPosition); furthestHouse = house; } } village.RemoveHouse(furthestHouse); } } //Find closest house to middle point of village and replace it foreach (VillageData village in chunkData.VillageList) { //Initialise VillageHouseData closestHouse = village.VillageHouses[0]; float closestDistance = float.MaxValue; foreach (VillageHouseData house in village.VillageHouses) { if (Vector3.Distance(house.transform.position, village.CenterPosition) < closestDistance) { closestDistance = Vector3.Distance(house.transform.position, village.CenterPosition); closestHouse = house; } } //Set center position for vilalge for this chunk village.LocalChunkCenterPosition = closestHouse.ChunkLocalPosition; //Delete closest house village.RemoveHouse(closestHouse); //Spawn village center prefab at location of closest house GameObject newCenter = Instantiate(ProceduralTerrain.Current.TerrainHouseData.VillageCenterPrefab.ObjectPrefab, closestHouse.transform.position, Quaternion.identity, closestHouse.transform.parent); village.VillageCenter = newCenter; chunkData.VillageCenterList.Add(newCenter); //Parent objects GameObject villageParent = new GameObject(); villageParent.transform.SetParent(village.VillageCenter.transform.parent); villageParent.name = "Village"; foreach (VillageHouseData house in village.VillageHouses) { house.transform.SetParent(villageParent.transform); } village.VillageCenter.transform.SetParent(villageParent.transform); } //Rotate houses to face village center foreach (VillageData village in chunkData.VillageList) { foreach (VillageHouseData house in village.VillageHouses) { house.transform.LookAt(village.VillageCenter.transform); //Make house flat, rather than tilted house.transform.localEulerAngles = new Vector3(0, house.transform.localEulerAngles.y, house.transform.localEulerAngles.z); } } //Make sure trees arent placed in village area int clearAreaRadius = ProceduralTerrain.Current.TerrainHouseData.ClearAreaRadiusAroundBuildings; foreach (VillageData village in chunkData.VillageList) { bool hasClearedAroundCenter = false; foreach (VillageHouseData house in village.VillageHouses) { Vector2 centerPosition = house.ChunkLocalPosition; //If the area around the village center hasnt been cleared yet, clear it if (!hasClearedAroundCenter) { centerPosition = village.LocalChunkCenterPosition; PreventSpawningInArea(chunkData, centerPosition, clearAreaRadius); //Set centerPosition back to this houses position centerPosition = house.ChunkLocalPosition; } //Prevent spawning of trees around this house PreventSpawningInArea(chunkData, centerPosition, clearAreaRadius); } } yield return(null); }
/// <summary> /// Extracts villages. /// </summary> /// <param name="content">Content to extract.</param> /// <returns>Extracted village data.</returns> public static VillageData[] Villages(string content) { string ownerName = GetMatch(content, "v owner name") .Groups["name"].Value; var mc = GetMatches(content, "v*"); var data = new VillageData[mc.Count]; for (int i = 0; i < mc.Count; i++) { var id = mc[i].Groups["id"].Value.AsInt(); var name = mc[i].Groups["name"].Value; var pop = mc[i].Groups["pop"].Value.AsInt(); bool central = mc[i].Groups["central"].Success; data[i++] = new VillageData(id, name, pop, ownerName, central); } return data; }
public VillagePropertyScreen(ref VillageData acreProperties) { this._acreProperties = acreProperties; }
public void AssignVillage(VillageData village) { Village = village; }
public static void BuyPlot(VillageData villageData) { EntrepreneurCampaignBehaviour entrepreneur = Campaign.Current.GetCampaignBehavior <EntrepreneurCampaignBehaviour>(); Dictionary <string, int> itemRequirements = new Dictionary <string, int>(); itemRequirements.Add("tools", 5); itemRequirements.Add("hardwood", 5); Dictionary <string, int> missingRequirements = new Dictionary <string, int>(); missingRequirements.Add("tools", 5); missingRequirements.Add("hardwood", 5); Dictionary <ItemRosterElement, int> itemsToRemove = new Dictionary <ItemRosterElement, int>(); foreach (KeyValuePair <string, int> requirement in itemRequirements) { IEnumerable <ItemRosterElement> items = Hero.MainHero.PartyBelongedTo.ItemRoster.AsQueryable().Where(item => item.Amount >= requirement.Value && item.EquipmentElement.Item.StringId.Equals(requirement.Key)); if (items.Count() != 0) { int currentAmount = items.First().Amount; itemsToRemove.Add(items.First(), currentAmount - requirement.Value); missingRequirements.Remove(requirement.Key); } } if (missingRequirements.Count == 0) { int buyPrice = villageData.AcreSellPrice; if (villageData.AvailableAcres > 0) { if (Hero.MainHero.Gold >= buyPrice) { villageData.buyAcre(); foreach (var item in itemsToRemove) { // Remove whole stack. Hero.MainHero.PartyBelongedTo.ItemRoster.Remove(item.Key); // Add the difference. Hero.MainHero.PartyBelongedTo.ItemRoster.AddToCounts(item.Key.EquipmentElement.Item, item.Value); } GiveGoldAction.ApplyForCharacterToSettlement(Hero.MainHero, Settlement.CurrentSettlement, buyPrice); } else { InformationManager.DisplayMessage(new InformationMessage("You dont have enouph gold to buy this plot.")); } } else { InformationManager.DisplayMessage(new InformationMessage("There are no plots acres to buy.")); } } else { foreach (KeyValuePair <string, int> requirement in missingRequirements) { InformationManager.DisplayMessage(new InformationMessage(($"You are missing {requirement.Value} items of {requirement.Key}."))); } } }
// 从AVObject拷贝数据 public static VillageData CreateFromAVObject(AVObject obj) { VillageData villageData = new VillageData(); villageData.AVObject = obj; return villageData; }
private List <Vector3> CreateVillageCenters(VillageGeneratorData villageGeneratorData, int villageCount) { List <Vector3> villagePositions = new List <Vector3>(); // TODO: Generalise spawnpoint bounds float lowerSpawnBoundX = 0 - chunkSize / 2; // When the time comes to add vertical scaling, this will have to change based on a separate vertical bound float lowerSpawnBoundY = 0; float lowerSpawnBoundZ = 0 - chunkSize / 2; // TODO: Generalise spawnpoint bounds float upperSpawnBoundX = 0 + chunkSize / 2; // When the time comes to add vertical scaling, this will have to change based on a separate vertical bound float upperSpawnBoundY = 0; float upperSpawnBoundZ = 0 + chunkSize / 2; Vector3 lowerBounds = new Vector3(lowerSpawnBoundX, lowerSpawnBoundY, lowerSpawnBoundZ); Vector3 upperBounds = new Vector3(upperSpawnBoundX, upperSpawnBoundY, upperSpawnBoundZ); // Loop over each village, generate a center for it for (int idx = 0; idx < villageCount; idx++) { float newVillageRadius = villageGeneratorData.spawnRadius.RandomSample(); Vector3 spawnPosition = UtilityFunctions.GetRandomVector3(lowerBounds, upperBounds); // Create Temp Area with the above parameters var tempArea = new TempRegion(RegionType.circle, newVillageRadius, spawnPosition); // Check for any collisions if (IsCircularRegionFree(tempArea)) { string newVillageName = $"{villageGeneratorData.villageName}.{idx}"; // Initialize new Village Center GameObject newVillageObject = new GameObject(name: newVillageName); var newVillageNode = newVillageObject.AddComponent <VillageNode>(); // Find new head count int newVillagerCount = villageGeneratorData.headCount.RandomSample(); newVillageNode.SetUp(newVillageName); newVillageNode.SetUpRegion(newVillageRadius, spawnPosition); var newVillageData = new VillageData { HeadCount = newVillagerCount, // huts will be grown as per necessity in the VillageNode script hutSpawnRange = villageGeneratorData.percentageHutSpawnRadius * (newVillageRadius / 100), villagersPerHut = villageGeneratorData.villagersPerHut, villagerPrefab = villageGeneratorData.villagerPrefab, elderHutPrefab = villageGeneratorData.elderHutPrefab, hutPrefab = villageGeneratorData.hutPrefab }; newVillageNode.SetUpVillage(newVillageData); newVillageNode.BeginGenerationProcess(); villagePositions.Add(newVillageNode.CenterPosition); Regions.Add(newVillageNode); AddLink(newVillageNode); } } return(villagePositions); }
public GroupData GetGroupByVillage(VillageData villageData) => _groupDataCoord.TryGetValue(new Tuple <int, int>(villageData.X, villageData.Y), out var group) ? group : null;