private void _reactToIncentives(IMessageBase baseMessage) { //Logger.Debug("react to incentives"); Incentives incentives = (Incentives)baseMessage; // do nothing }
private void RemoveActiveStrategy() { if (_activeStrategy == null) { return; } var revokePerPlayer = EventMap.Instance.RevokeStrategyEvents(_activeStrategy.strategyId, Time.CurrentTurn); foreach (int playerId in revokePerPlayer.Keys) { if (revokePerPlayer.TryGetValue(playerId, out List <TimedEvent> events)) { Incentives incentives = new Incentives(events) { UserId = playerId }; BackendWorker.GetInstance().SendReliable(incentives); } } EventMap.Instance.CleanupWithStrategyId(_activeStrategy.strategyId); _activeStrategy.Deinitialize(); _activeStrategy = null; }
public bool SaveOrUpdateIncentive(Incentives record, DbActionFlag flag) { try { if (DbActionFlag.Create == flag) { _context.Incentives.Add(record); } else if (DbActionFlag.Update == flag) { _context.Entry(record).State = System.Data.Entity.EntityState.Modified; } else if (DbActionFlag.Delete == flag) { _context.Incentives.Remove(record); } _context.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public void _handleIncentives(IMessageBase message) { //Logger.Debug("handle incentives"); Incentives incentives = (Incentives)message; List <RevokeEvent> revokeEvents = new List <RevokeEvent>(); List <TimedEvent> actuationEvents = new List <TimedEvent>(); foreach (TimedEvent newEvent in incentives.Events) { var newTimedEvent = (TimedEvent)newEvent; if (newEvent is RevokeEvent) { revokeEvents.Add((RevokeEvent)newTimedEvent); } else { actuationEvents.Add(newTimedEvent); } } lock (_events) { _events.RemoveAll(event_ => revokeEvents.TrueForOne( revokeEvent => revokeEvent.Id == event_.Id ) ); foreach (TimedEvent newEvent in actuationEvents) { TimedEvent eventToOverwrite = _events.Find(existingEvent => newEvent.StrategyId == existingEvent.StrategyId && newEvent.Id == existingEvent.Id); if (eventToOverwrite == null) { _events.Add(newEvent); } else { eventToOverwrite.OverrideWith(newEvent); } } } //double minDistance = double.MaxValue; //Vector minPosition = null; //Vector currentPosition = CurrentPosition; //foreach (Vector position in positions) //{ // double distance = (currentPosition - position).SqrMagnitude; // if (distance < minDistance) // { // minDistance = distance; // minPosition = position; // } //} // _recommendedPosition = minPosition; }
private Incentives _GetPlayerIncentives(int playerId) { Incentives playerIncentives; if (!_idToIncentives.TryGetValue(playerId, out playerIncentives)) { playerIncentives = new Incentives(); _idToIncentives[playerId] = playerIncentives; } return(playerIncentives); }
public double GetTotalIncomeEmployee(string employeeId) { var payRoll = new Payroll(); var benefit = new Benefits(); var incentive = new Incentives(); var salary = payRoll.GetSalaryEmployee(employeeId); var totalBenefis = benefit.GetBenefitsEmployee(employeeId).Sum(p => p.Value); // var totalIncetives = incentive.GetIncentivesEmployee(employeeId).Sum(p => p.Value); return(salary + totalBenefis); }
public void AddEvent(int playerId, TimedEvent newEvent) { if (playerId < 0) { Logger.Warn("Event doesn't have a valid player id."); return; } Incentives playerIncentives = _GetPlayerIncentives(newEvent.PlayerId); if (!playerIncentives.Events.Contains(newEvent)) { playerIncentives.Events.Add(newEvent); } }
private void _UpdateLoop() { if (_standardIntersectionStrategyHasChanged) { lock (_intersectionLock) { _standardIntersectionStrategyHasChanged = false; } } StrategyManager.Instance.ActiveStrategy?.UpdateState(); StrategyManager.Instance.ActiveStrategy?.UpdateIncentives(); //StrategyManager.Instance.Fallback.GetIncentivesForPlayers(); /* send incentives */ List <TimedEvent> eventsToSendToFrontend = new List <TimedEvent>(); foreach (KeyValuePair <int, Incentives> playerIncentivesPair in EventBundler.Instance.GetIdToIncentivesPairs()) { eventsToSendToFrontend.AddRange(playerIncentivesPair.Value.Events); if (PlayerData.Instance.TryGetEntry(playerIncentivesPair.Key, out PlayerDataEntry entry)) { Incentives incentivesToSend = playerIncentivesPair.Value; incentivesToSend.UserId = playerIncentivesPair.Key; entry.Incentives = playerIncentivesPair.Value; SendReliable(incentivesToSend); } } //FrontendAccess.Instance.AddEvents(eventsToSendToFrontend); if (eventsToSendToFrontend.Count > 0) { //Logger.Debug($"Sending {eventsToSendToFrontend.Count} to frontend"); SendToFrontend(new Incentives { Events = eventsToSendToFrontend }); } EventBundler.Instance.Reset(); /* cleanup old allocations */ EventMap.Instance.CleanupUntil(Time.CurrentTurn - 2); }
public bool Contains(TimedEvent event_) { Incentives playerIncentives = _GetPlayerIncentives(event_.PlayerId); return(playerIncentives.Events.Contains(event_)); }