private double[] CalculateChances(int amountOfPlayers) { chances = new Chances(allCards); bool isPair = currentHands[1]; bool isTwoPair = currentHands[2]; bool isThreeOfAKind = currentHands[3]; bool isStraight = currentHands[4]; bool isFlush = currentHands[5]; bool isFullHouse = currentHands[6]; bool isFourOfAKind = currentHands[7]; bool isStraightFlush = currentHands[8]; double pair = isPair ? 100.0 : chances.CalculateChanceForPair(amountOfPlayers, allCards); double twoPair = isTwoPair ? 100.0 : chances.CalculateChanceForTwoPair(amountOfPlayers, allCards); double threeOfAKind = isThreeOfAKind ? 100.0 : chances.CalculateChanceForThreeOfAKind(amountOfPlayers, isPair, isTwoPair, allCards); double straight = isStraight ? 100.0 : chances.CalculateChanceForStraight(amountOfPlayers, allCards); double flush = isFlush ? 100.0 : chances.CalculateChanceForFlush(amountOfPlayers, allCards); double fullHouse = isFullHouse ? 100 : chances.CalculateChanceForFullHouse(amountOfPlayers, allCards); double fourOfAKind = isFourOfAKind ? 100 : chances.CalculateChanceForFourOfAKind(amountOfPlayers, isThreeOfAKind, allCards); double straightFlush = isStraightFlush ? 100 : chances.CalculateChanceForStraightFlush(amountOfPlayers, allCards); double[] arrayChances = { pair, twoPair, threeOfAKind, straight, flush, fullHouse, fourOfAKind, straightFlush }; return(arrayChances); }
public int upChances(Chances c) { if (DALBase.Update(c) > 0) { return(0); } else { return(-1); }; }
public int UpdatePart(Chances chance) { if (Session["user"] == null) { return(-1000); } if (!PowerDAL.HasPower((Session["user"] as Users).RoleID.Value, 5)) { return(-1001); } return(ChancesDAL.UpdateSaleChance(chance)); }
/// <summary> /// 修改未分配销售机会信息 /// </summary> public static int UpdateSaleChance(Chances chance) { Chances old = BaseDAL.Find <Chances>(chance.ChanID); old.ChanName = chance.ChanName; old.ChanLinkMan = chance.ChanLinkMan; old.ChanLinkTel = chance.ChanLinkTel; old.ChanTitle = chance.ChanTitle; old.ChanDesc = chance.ChanDesc; old.ChanRate = chance.ChanRate; return(BaseDAL.Update(old)); }
public int Insert(Chances chance) { if (Session["user"] == null) { return(-1000); } if (!PowerDAL.HasPower((Session["user"] as Users).RoleID.Value, 5)) { return(-1001); } chance.ChanCreateMan = (Session["user"] as Users).UserID; return(ChancesDAL.InsertSaleChance(chance)); }
public void Initialize(ReferenceManager referenceManager) { reference = referenceManager; waveManager = reference.waveManager; Random.InitState((int)DateTime.Now.Ticks); intSpawnChance = (int)(spawnChance * 100); intPowerupSpawnChance = (int)(powerupSpawnChance * 100); enemySpawnChances = new Chances[enemySpawnChanceSetup.Length]; typeIds = new int[enemySpawnChanceSetup.Length]; int high = 0; for (int i = 0; i < enemySpawnChances.Length; ++i) { int low = high; high += (int)(enemySpawnChanceSetup[i].percentChance * 100); typeIds[i] = waveManager.EnemyIDs[(int)enemySpawnChanceSetup[i].enemyType]; enemySpawnChances[i] = new Chances(low, high, enemySpawnChanceSetup[i].firstWave); } powerupSpawnChances = new Chances[powerupSpawnChanceSetup.Length]; powerupPrefabs = new GameObject[powerupSpawnChanceSetup.Length]; high = 0; for (int i = 0; i < powerupSpawnChanceSetup.Length; ++i) { int low = high; high += (int)(powerupSpawnChanceSetup[i].percentChance * 100); powerupPrefabs[i] = waveManager.powerupPrefabs[(int)powerupSpawnChanceSetup[i].powerup]; powerupSpawnChances[i] = new Chances(low, high, powerupSpawnChanceSetup[i].firstWave); } paths = new Hashtable { { "child", false } }; foreach (string zone in waveManager.PathNames) { for (int num = 0; num < 13; ++num) { string path = zone + num; paths.Add(path, false); } } }
/// <summary> /// 分配人 /// </summary> public static int UpdateChanDueMan(int?chanDueMan, int chanID) { Chances ch = BaseDAL.Find <Chances>(chanID); if (chanDueMan == null) { ch.ChanState = 1; ch.ChanDueDate = null; ch.ChanDueMan = null; } else { ch.ChanState = 2; ch.ChanDueDate = DateTime.Now; ch.ChanDueMan = chanDueMan; } return(BaseDAL.Update(ch)); }
public int inChances(Chances c) { Chances b = new Chances() { ChanCreateMan = Convert.ToInt32(Session["id"]), ChanName = c.ChanName, ChanLinkMan = c.ChanLinkMan, ChanRate = c.ChanRate, ChanLinkTel = c.ChanLinkTel, ChanTitle = c.ChanTitle, ChanDesc = c.ChanDesc, }; if (DALBase.Insert(b) > 0) { return(Convert.ToInt32(DBHelp.ExecuteObject("select max(ChanID) from dbo.Chances"))); } else { return(-1); }; }
/// <summary> /// 此方法用于修改销售机会表 /// </summary> /// <param name="obj"></param> /// <returns></returns> public static int ChanAddNew(Chances obj) { return ChancesDAL.ChanAddNew(obj); }
public static List <string> ChooseTraitsFromEggToEgg(GameObject inst) { Debug.Log("ChooseTraitsFromEggToEgg"); var gtc = inst.AddOrGet <GeneticTraitComponent>(); var result = new List <string>(); var fromTraits = inst.GetComponent <AIGeneticTraits>(); Debug.Log("All groups"); var groups = Group.groups; Util.Shuffle <Group>(groups); DebugHelper.LogForEach(groups); if (fromTraits == null) { Debug.Log("No traits present"); } else { Debug.Log("Traits presents"); var traits_present = fromTraits.GetTraitIds(); var traits_locked = new List <GeneticTraitBuilder>(); var groups_locked_list = new List <Group>(); foreach (String t in traits_present) { var trait_locked = traits.Where(x => x.ID == t).FirstOrDefault(); traits_locked.Add(trait_locked); result.Add(t); groups_locked_list.Add(trait_locked.Group); Debug.Log(trait_locked); } Debug.Log("groups_locked"); DebugHelper.LogForEach(groups_locked_list); //groups = groups.Except(groups_locked); List <Group> result_ = groups.Except(groups_locked_list).ToList(); groups = result_; } Debug.Log("groups"); DebugHelper.LogForEach(groups); Chances chances = new Chances(); chances.addChance(0.5f); //1 positive trait chances.addChance(0.25f); //2 positives and 1 negative chances.addChance(0.25f); //None var chance_result = chances.rollChance(); chance_result = 0;//for testing purposes Debug.Log("chance_result " + chance_result); var number_positives = 0; var number_negatives = 0; switch (chance_result) { case 0: number_positives = 1; break; case 1: number_positives = 2; number_negatives = 1; break; case 2: break; } groups.OrderBy(x => Util.GaussianRandom());//is not ordering randomly must be fix var groups_list = groups.ToList(); for (int i = 0; i < number_positives && groups_list.Count() > 0; i++) { var first = groups_list.First(); var temp = ChooseTraitFromGroup(groups.First(), true, true); if (temp != null) { result.Add(temp); } groups_list = groups_list.Where(u => u.Id != first.Id).ToList(); } //for testing result.Clear(); result.Add((new OffColor()).ID); for (int i = 0; i < number_negatives && groups.Count() > 0; i++) { var first = groups.First(); var temp = ChooseTraitFromGroup(groups.First(), true, false); if (temp != null) { result.Add(temp); } groups = groups.Where(u => u.Id != first.Id).ToList(); } /* int numTraitsToChoose = UnityEngine.Random.Range(2, 4); * Debug.Log("------------"); * Debug.Log(inst); * Debug.Log(numTraitsToChoose); * * * foreach (var group in groups) * { * if (group.Key.HasRequirements(inst)) * { * result.Add(ChooseTraitFrom(group)); * } * }*/ Debug.Log(result); DebugHelper.LogForEach(result); // If there are more traits than asked for we don't want to bias to the ones that were chosen first return(result .Where(s => s != null) //.OrderBy(x => Util.GaussianRandom()) //.Take(numTraitsToChoose) .ToList()); }
public static int HandleWorkers(PrivateBuildingAI thisAI, ushort buildingID, ref Building buildingData, ref Citizen.BehaviourData behaviour, ref int aliveWorkerCount, ref int totalWorkerCount, ref int workPlaceCount) { //Not messed with this code too much yet. Still requires cleaning up. int b = 0; int level0, level1, level2, level3; //Fix for crashing? Modification added for this statement if (thisAI != null) { GetWorkBehaviour(thisAI, buildingID, ref buildingData, ref behaviour, ref aliveWorkerCount, ref totalWorkerCount); thisAI.CalculateWorkplaceCount(new Randomizer((int)buildingID), buildingData.Width, buildingData.Length, out level0, out level1, out level2, out level3); workPlaceCount = level0 + level1 + level2 + level3; if ((int)buildingData.m_fireIntensity == 0) { HandleWorkPlaces(thisAI, buildingID, ref buildingData, level0, level1, level2, level3, ref behaviour, aliveWorkerCount, totalWorkerCount); if (aliveWorkerCount != 0 && workPlaceCount != 0) { int num = (behaviour.m_efficiencyAccumulation + aliveWorkerCount - 1) / aliveWorkerCount; b = 2 * num - 200 * num / ((100 * aliveWorkerCount + workPlaceCount - 1) / workPlaceCount + 100); } } Notification.Problem problems1 = Notification.RemoveProblems(buildingData.m_problems, Notification.Problem.NoWorkers | Notification.Problem.NoEducatedWorkers); int num1 = (level3 * 300 + level2 * 200 + level1 * 100) / (workPlaceCount + 1); int num2 = (behaviour.m_educated3Count * 300 + behaviour.m_educated2Count * 200 + behaviour.m_educated1Count * 100) / (aliveWorkerCount + 1); //Start of modification if (Chances.WorkHour()) { if (aliveWorkerCount < workPlaceCount >> 1) { buildingData.m_workerProblemTimer = (byte)Mathf.Min((int)byte.MaxValue, (int)buildingData.m_workerProblemTimer + 1); if ((int)buildingData.m_workerProblemTimer >= 128) { problems1 = Notification.AddProblems(problems1, Notification.Problem.NoWorkers | Notification.Problem.MajorProblem); } else if ((int)buildingData.m_workerProblemTimer >= 64) { problems1 = Notification.AddProblems(problems1, Notification.Problem.NoWorkers); } } else if (num2 < num1 - 50) { buildingData.m_workerProblemTimer = (byte)Mathf.Min((int)byte.MaxValue, (int)buildingData.m_workerProblemTimer + 1); if ((int)buildingData.m_workerProblemTimer >= 128) { problems1 = Notification.AddProblems(problems1, Notification.Problem.NoEducatedWorkers | Notification.Problem.MajorProblem); } else if ((int)buildingData.m_workerProblemTimer >= 64) { problems1 = Notification.AddProblems(problems1, Notification.Problem.NoEducatedWorkers); } } } //End of modification buildingData.m_problems = problems1; } return(Mathf.Max(1, b)); }
/// <summary> /// 修改销售机会 /// </summary> /// <param name="obj"></param> /// <returns></returns> public static bool ChancesDueManUpdate(Chances obj) { return ChancesDAL.ChancesDueManUpdate(obj); }
/// <summary> /// 此方法用于修改销售机会表 /// </summary> /// <param name="obj"></param> /// <returns>返回受影响的行数</returns> public static int ChancesEdit(Chances obj) { return ChancesDAL.ChancesEdit(obj); }
public int ChancesAddNew(Chances obj) { object userid = Session["UserID"]; obj.ChanCreateMan=Convert.ToInt32(userid); return ChancesBLL.ChanAddNew(obj); }
public int ChancesEdit(Chances obj) { return ChancesBLL.ChancesEdit(obj); }
public static bool ProcessHome(ref ResidentAI thisAI, uint citizenID, ref Citizen person) { CitizenManager _citizenManager = Singleton <CitizenManager> .instance; SimulationManager _simulation = Singleton <SimulationManager> .instance; if ((person.m_flags & Citizen.Flags.MovingIn) != Citizen.Flags.None) { _citizenManager.ReleaseCitizen(citizenID); } else if (ProcessGenerics(ref thisAI, citizenID, ref person)) { if ((person.m_flags & Citizen.Flags.NeedGoods) != Citizen.Flags.None && (!Chances.WorkDay(ref person) || _simulation.m_currentDayTimeHour > Chances.m_startWorkHour)) //Wants to go shopping { if (person.m_homeBuilding != 0 && person.m_instance == 0 && person.m_vehicle == 0) //Person isn't already out and about { if (_simulation.m_isNightTime) { uint chance = _simulation.m_randomizer.UInt32(1000); if (chance < Chances.GoOutAtNight(person.Age) && NewResidentAI.DoRandomMove(thisAI)) { //Only go locally to find a shop at night FindCloseVisitPlace(ref thisAI, citizenID, ref person, person.m_homeBuilding, 1000f); return(true); } } else if (NewResidentAI.DoRandomMove(thisAI)) { uint chance = _simulation.m_randomizer.UInt32(100); if (chance < 10) { uint localChance = _simulation.m_randomizer.UInt32(100); ushort localVisitPlace = 0; if (ExperimentsToggle.AllowLocalBuildingSearch && localChance < ExperimentsToggle.LocalBuildingPercentage) { LoggingWrapper.Log("Citizen " + citizenID + " trying to find a local commercial building."); localVisitPlace = FindCloseVisitPlace(ref thisAI, citizenID, ref person, person.m_homeBuilding, 1000f); } if (localVisitPlace == 0) { LoggingWrapper.Log("Citizen " + citizenID + " going to a random commercial building."); NewResidentAI.FindVisitPlace(thisAI, citizenID, person.m_homeBuilding, NewResidentAI.GetShoppingReason(thisAI)); } return(true); } } } } else if (person.m_homeBuilding != 0 && person.m_instance != 0 && person.m_vehicle == 0 || NewResidentAI.DoRandomMove(thisAI)) //If the person is already out and about, or can move (based on entities already visible) { int eventId = CityEventManager.instance.EventStartsWithin(citizenID, ref person, StartMovingToEventTime); if (eventId != -1) { CityEvent _cityEvent = CityEventManager.instance.m_nextEvents[eventId]; if (_cityEvent.EventStartsWithin(StartMovingToEventTime) && !_cityEvent.EventStartsWithin(MaxMoveToEventTime)) { if ((person.m_instance != 0 || NewResidentAI.DoRandomMove(thisAI)) && _cityEvent.Register(citizenID, ref person)) { NewResidentAI.StartMoving(thisAI, citizenID, ref person, person.m_homeBuilding, _cityEvent.m_eventData.m_eventBuilding); person.SetVisitplace(citizenID, _cityEvent.m_eventData.m_eventBuilding, 0U); person.m_visitBuilding = _cityEvent.m_eventData.m_eventBuilding; return(true); } } } else { if (person.m_workBuilding != 0 && !_simulation.m_isNightTime && !Chances.ShouldReturnFromWork(ref person)) { if (Chances.ShouldGoToWork(ref person)) { NewResidentAI.StartMoving(thisAI, citizenID, ref person, person.m_homeBuilding, person.m_workBuilding); return(true); } } else { if (Chances.ShouldGoFindEntertainment(ref person)) { if (_simulation.m_isNightTime) { FindLeisure(ref thisAI, citizenID, ref person, person.m_homeBuilding); } else { NewResidentAI.FindVisitPlace(thisAI, citizenID, person.m_homeBuilding, NewResidentAI.GetEntertainmentReason(thisAI)); } return(true); } } } } } return(false); }
public static bool ProcessWork(ref ResidentAI thisAI, uint citizenID, ref Citizen person) { CitizenManager _citizenManager = Singleton <CitizenManager> .instance; BuildingManager _buildingManager = Singleton <BuildingManager> .instance; SimulationManager _simulation = Singleton <SimulationManager> .instance; if (ProcessGenerics(ref thisAI, citizenID, ref person)) { if (person.m_instance != 0 || NewResidentAI.DoRandomMove(thisAI)) //If the person is already out and about, or can move (based on entities already visible) { if (Chances.ShouldReturnFromWork(ref person)) { int eventId = CityEventManager.instance.EventStartsWithin(citizenID, ref person, StartMovingToEventTime); if (eventId != -1) { CityEvent _cityEvent = CityEventManager.instance.m_nextEvents[eventId]; if (_cityEvent.EventStartsWithin(StartMovingToEventTime) && !_cityEvent.EventStartsWithin(MaxMoveToEventTime)) { if ((person.m_instance != 0 || NewResidentAI.DoRandomMove(thisAI)) && _cityEvent.Register(citizenID, ref person)) { NewResidentAI.StartMoving(thisAI, citizenID, ref person, person.m_workBuilding, _cityEvent.m_eventData.m_eventBuilding); person.SetVisitplace(citizenID, _cityEvent.m_eventData.m_eventBuilding, 0U); person.m_visitBuilding = _cityEvent.m_eventData.m_eventBuilding; } } } else { if (Chances.ShouldGoFindEntertainment(ref person)) { uint localChance = _simulation.m_randomizer.UInt32(100); ushort localVisitPlace = 0; if (ExperimentsToggle.AllowLocalBuildingSearch && localChance < ExperimentsToggle.LocalBuildingPercentage) { LoggingWrapper.Log("Citizen " + citizenID + " trying to find a local commercial building."); localVisitPlace = FindCloseVisitPlace(ref thisAI, citizenID, ref person, person.m_workBuilding, 1000f); } if (localVisitPlace == 0) { LoggingWrapper.Log("Citizen " + citizenID + " going to a random commercial building."); NewResidentAI.FindVisitPlace(thisAI, citizenID, person.m_workBuilding, NewResidentAI.GetEntertainmentReason(thisAI)); } return(true); } else { if ((person.m_flags & Citizen.Flags.NeedGoods) != Citizen.Flags.None) //Wants to go shopping { if (person.m_workBuilding != 0 && person.m_instance == 0 && person.m_vehicle == 0) //Person isn't already out and about { uint localChance = _simulation.m_randomizer.UInt32(100); ushort localVisitPlace = 0; if (ExperimentsToggle.AllowLocalBuildingSearch && localChance < ExperimentsToggle.LocalBuildingPercentage) { LoggingWrapper.Log("Citizen " + citizenID + " trying to find a local commercial building."); localVisitPlace = FindCloseVisitPlace(ref thisAI, citizenID, ref person, person.m_workBuilding, 1000f); } if (localVisitPlace == 0) { LoggingWrapper.Log("Citizen " + citizenID + " going to a random commercial building."); NewResidentAI.FindVisitPlace(thisAI, citizenID, person.m_workBuilding, NewResidentAI.GetShoppingReason(thisAI)); } } return(true); } else { NewResidentAI.StartMoving(thisAI, citizenID, ref person, person.m_workBuilding, person.m_homeBuilding); return(true); } } } } else if (Chances.ShouldGoToLunch(ref person) && person.m_workBuilding != 0) { //Try find somewhere close to eat ushort foundLunchPlace = FindCloseVisitPlace(ref thisAI, citizenID, ref person, person.m_workBuilding, 200f); if (foundLunchPlace != 0) { LoggingWrapper.Log("Citizen " + citizenID + " is heading out to eat for lunch at " + CityEventManager.CITY_TIME.ToShortTimeString() + "."); return(true); } else { LoggingWrapper.Log("Citizen " + citizenID + " wanted to head out for lunch, but there were no buildings close enough."); } } } } return(false); }
public static bool ProcessVisit(ref ResidentAI thisAI, uint citizenID, ref Citizen person) { if (ProcessGenerics(ref thisAI, citizenID, ref person)) { SimulationManager _simulation = Singleton <SimulationManager> .instance; WeatherManager _weatherManager = Singleton <WeatherManager> .instance; BuildingManager _buildingManager = Singleton <BuildingManager> .instance; ItemClass.Service service = ItemClass.Service.None; if (person.m_visitBuilding != 0) { service = _buildingManager.m_buildings.m_buffer[person.m_visitBuilding].Info.m_class.m_service; } if (service == ItemClass.Service.PoliceDepartment || service == ItemClass.Service.HealthCare) { if (person.m_homeBuilding != 0 && person.m_instance == 0 && person.m_vehicle == 0) { NewResidentAI.StartMoving(thisAI, citizenID, ref person, person.m_visitBuilding, person.m_homeBuilding); person.SetVisitplace(citizenID, 0, 0U); return(true); } } if (service == ItemClass.Service.Disaster) { if (_buildingManager.m_buildings.m_buffer[person.m_visitBuilding].m_flags.IsFlagSet(Building.Flags.Downgrading) && person.m_homeBuilding != 0 && person.m_vehicle == 0) { NewResidentAI.StartMoving(thisAI, citizenID, ref person, person.m_visitBuilding, person.m_homeBuilding); person.SetVisitplace(citizenID, 0, 0U); } } else if (!GameEventHelpers.EventTakingPlace(person.m_visitBuilding) && !CityEventManager.instance.EventTakingPlace(person.m_visitBuilding) && !CityEventManager.instance.EventStartsWithin(person.m_visitBuilding, 2D)) { int eventId = CityEventManager.instance.EventStartsWithin(citizenID, ref person, StartMovingToEventTime); bool eventOn = false; if (eventId != -1) { CityEvent _cityEvent = CityEventManager.instance.m_nextEvents[eventId]; if (_cityEvent.EventStartsWithin(StartMovingToEventTime) && !_cityEvent.EventStartsWithin(MaxMoveToEventTime)) { if ((person.m_instance != 0 || NewResidentAI.DoRandomMove(thisAI)) && _cityEvent.Register(citizenID, ref person)) { NewResidentAI.StartMoving(thisAI, citizenID, ref person, person.m_visitBuilding, _cityEvent.m_eventData.m_eventBuilding); person.SetVisitplace(citizenID, _cityEvent.m_eventData.m_eventBuilding, 0U); person.m_visitBuilding = _cityEvent.m_eventData.m_eventBuilding; eventOn = true; } } } if (!eventOn) { if (person.m_instance != 0 && _weatherManager.m_currentRain > 0 && _simulation.m_randomizer.Int32(0, 10) <= (_weatherManager.m_currentRain * 10)) { //It's raining, we're outside, and we need to go somewhere dry! if (person.m_workBuilding != 0 && !_simulation.m_isNightTime && !Chances.ShouldReturnFromWork(ref person)) { NewResidentAI.StartMoving(thisAI, citizenID, ref person, person.m_visitBuilding, person.m_workBuilding); LoggingWrapper.Log("Rain! Citizen " + citizenID + " is getting wet, and has decided to go back to work."); } else { NewResidentAI.StartMoving(thisAI, citizenID, ref person, person.m_visitBuilding, person.m_homeBuilding); LoggingWrapper.Log("Rain! Citizen " + citizenID + " is getting wet, and has decided to go home."); } person.SetVisitplace(citizenID, 0, 0U); } else if (person.m_workBuilding != 0 && (Chances.ShouldGoToWork(ref person) || ((Chances.LunchHour() || Chances.HoursSinceLunchHour(1.5f)) && Chances.ShouldGoToWork(ref person, true)))) { NewResidentAI.StartMoving(thisAI, citizenID, ref person, person.m_visitBuilding, person.m_workBuilding); person.SetVisitplace(citizenID, 0, 0U); LoggingWrapper.Log("Citizen " + citizenID + " was out and about but should've been at work. Going there now."); } else if ((person.m_flags & Citizen.Flags.NeedGoods) != Citizen.Flags.None) { if (person.m_visitBuilding == 0) { person.CurrentLocation = Citizen.Location.Home; } else { BuildingManager instance = Singleton <BuildingManager> .instance; BuildingInfo info = instance.m_buildings.m_buffer[person.m_visitBuilding].Info; int amountDelta = -100; info.m_buildingAI.ModifyMaterialBuffer(person.m_visitBuilding, ref instance.m_buildings.m_buffer[person.m_visitBuilding], TransferManager.TransferReason.Shopping, ref amountDelta); } return(true); } else if ((person.m_instance != 0 || NewResidentAI.DoRandomMove(thisAI)) && person.m_homeBuilding != 0 && person.m_vehicle == 0) { uint shouldStayPercent = 2; if (Chances.CanStayOut(ref person) && _simulation.m_randomizer.UInt32(100) < shouldStayPercent) { if (Chances.ShouldGoFindEntertainment(ref person)) { if (_simulation.m_isNightTime) { FindLeisure(ref thisAI, citizenID, ref person, person.m_visitBuilding); } else { NewResidentAI.FindVisitPlace(thisAI, citizenID, person.m_visitBuilding, NewResidentAI.GetEntertainmentReason(thisAI)); } return(true); } } else { NewResidentAI.StartMoving(thisAI, citizenID, ref person, person.m_visitBuilding, person.m_homeBuilding); person.SetVisitplace(citizenID, 0, 0U); return(true); } } } } } person.m_flags &= Citizen.Flags.Unemployed | Citizen.Flags.Wealth | Citizen.Flags.Location | Citizen.Flags.NoElectricity | Citizen.Flags.NoWater | Citizen.Flags.NoSewage | Citizen.Flags.BadHealth | Citizen.Flags.Created | Citizen.Flags.Tourist | Citizen.Flags.Sick | Citizen.Flags.Dead | Citizen.Flags.Student | Citizen.Flags.MovingIn | Citizen.Flags.DummyTraffic | Citizen.Flags.Criminal | Citizen.Flags.Arrested | Citizen.Flags.Evacuating | Citizen.Flags.Collapsed | Citizen.Flags.Education1 | Citizen.Flags.Education2 | Citizen.Flags.Education3 | Citizen.Flags.Original | Citizen.Flags.CustomName; return(false); }
/// <summary> /// 得到失败原因 /// </summary> public static string GetChanError(int chanID) { Chances chan = BaseDAL.Find <Chances>(chanID); return(chan == null ? string.Empty : chan.ChanError); }
/// <summary> /// Ход игрока /// </summary> /// <param name="user"></param> public void NewMove(User user) { int[] dices; int prisonCounter = 0; //Для дублей do { if (user.IsInPrison) { if (user.IdleCount == 0 || user.JailReleasePermisson) { JailRelease?.Invoke(user); if (user.JailReleasePermisson) { Console.WriteLine("Вы воспользовались освобождением из тюрьмы"); user.JailReleasePermisson = false; return; } else { Console.WriteLine("Вы особождены по истечению срока"); } user.IsInPrison = false; return; } if (BuybackFromPrison?.Invoke(user) == true) { if (user.Money < 50) { NoEnoughMoney?.Invoke(user); Console.WriteLine("Нет денег"); return; } else { Console.WriteLine("Вы освобождены"); } user.Money -= 50; user.IdleCount = 0; user.IsInPrison = false; JailRelease?.Invoke(user); return; } else { if (user.IdleCount > 0) { user.IdleCount--; } return; } } Console.WriteLine($"\n{user.Name} старая позиция {user.Position}"); Console.WriteLine("{0} бросает кубики", user.Name); dices = DiceRoll(); Console.WriteLine("Первый кубик - {0}, второй - {1}", dices[0], dices[1]); int move_count = dices[0] + dices[1]; Dice?.Invoke(user, dices[0], dices[1]); int curr_position; user.Position += move_count; curr_position = user.Position; if (curr_position > 39) { user.Position = curr_position - 39; user.Money += 200; } //Зацикливание //test //user.position = 5; //заглушка для полей, которых еще нет //if (user.position > 10) //{ // console.writeline("больше 10"); // return; //} var Cell = Cells.Find(c => c.ID == user.Position); Console.WriteLine("Вы находитесь на {0}", Cell.Name); CurrentCell?.Invoke(user, Cell); Console.WriteLine(Cell.GetType().Name); //Клетку тюрьмы prisonCounter++; if (prisonCounter == 3 || Cell is Prison) { if (!user.IsInPrison && !user.JailReleasePermisson) { var prison = Cell as Prison; user.Position = Cells.Find(c => c.ID == 10).ID; user.IsInPrison = true; user.IdleCount = 2; SetPrison?.Invoke(user); Console.WriteLine("Вы в тюрьме"); } return; } //Попадание на клетку шанса\общественной казны if (Cell is CardPick) { var CardPickCard = Cell as CardPick; GetCardPick?.Invoke(user, CardPickCard); int r; Card chanceCard; switch (CardPickCard.Type) { case Models.Cells.Type.CommunityChest: r = random.Next(1, CommunityChest.Count); chanceCard = CommunityChest.Find(c => c.Id == r); //if(chanceCard != null) //Console.WriteLine($"{user.Name} попал на клетку общественной казны '{chanceCard.Name}'"); break; default: r = random.Next(1, Chances.Count); chanceCard = Chances.Find(c => c.Id == r); //if (chanceCard != null) //Console.WriteLine($"{user.Name} попал на клетку Шанс'{chanceCard.Name}'"); break; } if (chanceCard != null) { Console.WriteLine($"{user.Name} попал на клетку {CardPickCard.Type} '{chanceCard.Name}'"); } if (chanceCard is Motion) { var motion = chanceCard as Motion; Console.WriteLine($"{motion.Name}"); user.Position = motion.Position; var newPosition = Cells.Find(c => c.ID == user.Position); CurrentCell?.Invoke(user, newPosition); if (Cells.Find(c => c.ID == user.Position) != null) { Console.WriteLine($"{user.Name} перемещается на клетку {newPosition.Name}"); } return; } if (chanceCard is Transaction) { var transaction = chanceCard as Transaction; if (transaction != null) { Console.WriteLine($"{transaction.Name}"); } int previousAmount = user.Money; Console.WriteLine($"{user.Name} старое количество денег - {previousAmount}"); if (user.Money < Math.Abs(transaction.Cost)) { NoEnoughMoney?.Invoke(user); RemoveFromGame?.Invoke(user); Console.WriteLine("У вас недостаточно денег!"); return; } user.Money += transaction.Cost; Transaction?.Invoke(user, previousAmount, user.Money); } if (chanceCard is PrisonCard) { var prison = Cell as Prison; if (prison != null) { user.Position = Cells.Find(c => c == prison).ID; } user.IsInPrison = true; user.IdleCount = 2; SetPrison?.Invoke(user); return; } if (chanceCard is JailRelease) { user.JailReleasePermisson = true; Console.WriteLine($"{chanceCard.Name}"); } if (chanceCard is MoveCard) { var first_postion = user.Position; var move = chanceCard as MoveCard; user.Position = first_postion + move.MoveOn; var newPosition = Cells.Find(c => c.ID == user.Position); CurrentCell?.Invoke(user, newPosition); if (Cells.Find(c => c.ID == user.Position) != null) { Console.WriteLine($"{user.Name} перемещается на клетку {newPosition.Name}"); } return; } } //Клетка газопровод if (Cell is Utilities) { var utility = Cell as Utilities; if (utility.Owner == null) { if (Buy?.Invoke(user) == true) { if (user.Money < utility.Cost) { NoEnoughMoney?.Invoke(user); Console.WriteLine("Нет денег"); return; } user.Money -= utility.Cost; utility.Owner = user; } } else { if (utility.Owner == user) { return; } List <Utilities> utilitiesOfOwner; int cost; utilitiesOfOwner = Cells.Where(a => a is Utilities).Select(a => { if (a is Utilities) { return(a as Utilities); } return(null as Utilities); }).Where(a => a.Owner == utility.Owner).ToList(); switch (utilitiesOfOwner.Count) { case 1: cost = 4 * move_count; break; case 2: cost = 10 * move_count; break; default: return; } if (user.Money < cost) { NoEnoughMoney?.Invoke(user); RemoveFromGame?.Invoke(user); Console.WriteLine("Нет денег"); return; } int previousAmount = user.Money; user.Money -= cost; Transaction?.Invoke(user, previousAmount, user.Money); int previousOwnersAmount = utility.Owner.Money; utility.Owner.Money += cost; Transaction?.Invoke(utility.Owner, previousOwnersAmount, utility.Owner.Money); } } //Клетка налога if (Cell is Tax) { var Tax = Cell as Tax; if (user.Money < Tax.Amount) { NoEnoughMoney?.Invoke(user); RemoveFromGame?.Invoke(user); Console.WriteLine("У вас недостаточно денег"); return; } int previousAmount = user.Money; user.Money -= Tax.Amount; Transaction?.Invoke(user, previousAmount, user.Money); } //Клетка Railway if (Cell is Railway) { var RailwayStation = Cell as Railway; if (RailwayStation.Owner == null) { if (Buy?.Invoke(user) == true) { if (user.Money < RailwayStation.Cost) { NoEnoughMoney?.Invoke(user); Console.WriteLine("Нет денег"); return; } user.Money -= RailwayStation.Cost; RailwayStation.Owner = user; } } else { if (RailwayStation.Owner == user) { return; } List <Railway> ownerOfRailways; ownerOfRailways = Cells.Where(a => a is Railway).Select(a => { if (a is Railway) { return(a as Railway); } return(null as Railway); }).Where(a => a.Owner == RailwayStation.Owner).ToList(); int cost; switch (ownerOfRailways.Count) { case 1: cost = 25; break; case 2: cost = 50; break; case 3: cost = 100; break; case 4: cost = 200; break; default: return; } if (user.Money < cost) { NoEnoughMoney?.Invoke(user); RemoveFromGame?.Invoke(user); Console.WriteLine("Вам нехватает денег"); return; } int previousUserMoney = user.Money; user.Money -= cost; Transaction?.Invoke(user, previousUserMoney, user.Money); int previousOwnerMoney = RailwayStation.Owner.Money; RailwayStation.Owner.Money += cost; Transaction?.Invoke(RailwayStation.Owner, previousOwnerMoney, RailwayStation.Owner.Money); } } //Попадания на клетку недвижимости if (Cell is Property) { var Location = Cell as Property; if (Location.Owner == null) { if (Buy?.Invoke(user) == true) { if (user.Money < Location.Price) { NoEnoughMoney?.Invoke(user); Console.WriteLine("Нет денег"); return; } user.Money -= Location.Price; Location.Owner = user; user.Properties.Add(Location); var needed = Monopolies .Where(m => m.PropertiesInMonopoly.Contains(Location.ID)) .ToArray()[0].PropertiesInMonopoly; var have = user.Properties.Select(s => s.ID).ToArray(); GetUsersProperties?.Invoke(user); if (!needed.Except(have).Any()) { Console.WriteLine("У вас монополия"); user.Properties.ForEach(i => { i.InMonopoly = true; }); } } //Логика торгов } else { if (Location.Owner == user) { return; } if (!Location.InMonopoly) { if (user.Money < Location.PropertyOnly) { NoEnoughMoney?.Invoke(user); RemoveFromGame?.Invoke(user); Console.WriteLine("Недостаточно денег"); return; } //user.Money -= Location.PropertyOnly; //Location.Owner.Money += Location.PropertyOnly; int previousUserMoney = user.Money; user.Money -= Location.PropertyOnly; Transaction?.Invoke(user, previousUserMoney, user.Money); int previousOwnerMoney = Location.Owner.Money; Location.Owner.Money += Location.PropertyOnly; Transaction?.Invoke(Location.Owner, previousOwnerMoney, Location.Owner.Money); } else { int cost; switch (Location.Houses) { case 1: cost = Location.OneHouse; break; case 2: cost = Location.TwoHouses; break; case 3: cost = Location.ThreeHouses; break; case 4: cost = Location.FourHouses; break; default: return; } if (Location.InMonopoly) { cost = Location.Hotel; } if (user.Money < cost) { NoEnoughMoney?.Invoke(user); RemoveFromGame?.Invoke(user); Console.WriteLine("Недостаточно денег"); return; } int previousUserMoney = user.Money; user.Money -= cost; Transaction?.Invoke(user, previousUserMoney, user.Money); int previousOwnerMoney = Location.Owner.Money; Location.Owner.Money += cost; Transaction?.Invoke(Location.Owner, previousOwnerMoney, Location.Owner.Money); } } } }while (dices[0] == dices[1] && !user.IsInPrison); }
/// <summary> /// 添加新的销售机会信息 /// </summary> public static int InsertSaleChance(Chances chance) { chance.ChanCreateDate = DateTime.Now; chance.ChanState = 1; return(BaseDAL.Insert(chance)); }