/// <summary> /// Validates an outpost /// </summary> /// <param name="state">The game state</param> /// <param name="outpost">The outpost to validate</param> /// <returns>If the outpost is valid</returns> public static bool ValidateOutpost(GameState.GameState state, Outpost outpost) { if (outpost == null) { return(false); } if (!state.OutpostExists(outpost)) { return(false); } if (outpost.GetComponent <DrillerCarrier>().GetDrillerCount() < 0) { return(false); } if (outpost.GetComponent <SpecialistManager>() == null) { return(false); } if (outpost.GetComponent <SpecialistManager>().GetSpecialistCount() < 0) { return(false); } if (outpost.GetComponent <SpecialistManager>().GetSpecialistCount() > outpost.GetComponent <SpecialistManager>().GetCapacity()) { return(false); } if (outpost.GetComponent <DrillerCarrier>().GetOwner() != null && !state.PlayerExists(outpost.GetComponent <DrillerCarrier>().GetOwner())) { return(false); } return(true); }
public override bool ForwardAction(TimeMachine timeMachine, GameState.GameState state) { Entity drillLocation = state.GetEntity(GetEventData().SourceId); if (drillLocation != null && drillLocation is Outpost && !(drillLocation is Mine) && !((Outpost)drillLocation).GetComponent <DrillerCarrier>().IsDestroyed()) { _original = (Outpost)drillLocation; var drillerCarrier = drillLocation.GetComponent <DrillerCarrier>(); if (state.GetOutposts().Contains(_original) && !drillerCarrier.GetOwner().IsEliminated() && drillerCarrier.GetDrillerCount() >= drillerCarrier.GetOwner().GetRequiredDrillersToMine()) { _drilledMine = new Mine(_original); if (state.ReplaceOutpost(_original, _drilledMine)) { drillerCarrier.RemoveDrillers(drillerCarrier.GetOwner().GetRequiredDrillersToMine()); drillerCarrier.GetOwner().AlterMinesDrilled(1); timeMachine.AddEvent(new NeptuniumProductionEvent(_drilledMine, GetOccursAt().Advance(Mine.TICKS_PER_PRODUCTION_PER_MINE / state.GetPlayerOutposts(drillerCarrier.GetOwner()).Count))); EventSuccess = true; } } } else { EventSuccess = false; } return(EventSuccess); }
/// <summary> /// Validates a sub /// </summary> /// <param name="state">The game state</param> /// <param name="sub">The sub to validate</param> /// <returns>If the sub is valid</returns> public static bool ValidateSub(GameState.GameState state, Sub sub) { if (sub == null) { return(false); } if (!state.SubExists(sub)) { return(false); } if (sub.GetComponent <DrillerCarrier>().GetDrillerCount() < 0) { return(false); } if (sub.GetComponent <SpecialistManager>() == null) { return(false); } if (sub.GetComponent <SpecialistManager>().GetSpecialistCount() < 0) { return(false); } if (sub.GetComponent <SpecialistManager>().GetSpecialistCount() > sub.GetComponent <SpecialistManager>().GetCapacity()) { return(false); } if (sub.GetComponent <DrillerCarrier>().GetOwner() != null && !state.PlayerExists(sub.GetComponent <DrillerCarrier>().GetOwner())) { return(false); } return(true); }
public override bool ForwardAction(TimeMachine timeMachine, GameState.GameState state) { if (!Validator.ValidateICombatable(state, _combatant1) || !Validator.ValidateICombatable(state, _combatant2)) { this.EventSuccess = false; return(false); } // Determine additional events that should be triggered for this particular combat. if (_combatant1.GetComponent <DrillerCarrier>().GetOwner() == _combatant2.GetComponent <DrillerCarrier>().GetOwner()) { this._actions.Add(new FriendlySubArrive(_combatant1, _combatant2, base.GetOccursAt())); } else { this._actions.Add(new SpecialistCombat(_combatant1, _combatant2)); this._actions.Add(new DrillerCombat(_combatant1, _combatant2)); this._actions.Add(new CombatCleanup(_combatant1, _combatant2)); } foreach (IReversible action in this._actions) { action.ForwardAction(timeMachine, state); } this.EventSuccess = true; return(true); }
public bool BackwardAction(TimeMachine timeMachine, GameState.GameState state) { if (!_eventSuccess) { return(false); } List <Specialist> specialists = new List <Specialist>(); specialists.AddRange(_combatant1Specialists); specialists.AddRange(_combatant2Specialists); while (specialists.Count > 0) { Specialist lowPriority = null; foreach (Specialist s in specialists) { if (lowPriority == null || s.GetPriority() >= lowPriority.GetPriority()) { lowPriority = s; } } // Apply the specialist effect to the enemey. Entity enemy = lowPriority != null && _combatant1.GetComponent <DrillerCarrier>().GetOwner() == lowPriority.GetOwner() ? _combatant2 : _combatant1; Entity friendly = lowPriority != null && _combatant1.GetComponent <DrillerCarrier>().GetOwner() == lowPriority.GetOwner() ? _combatant1 : _combatant2; if (lowPriority != null) { lowPriority.UndoEffect(state, friendly, enemy); } } return(true); }
public override bool BackwardAction(TimeMachine timeMachine, GameState.GameState state) { if (EventSuccess) { _mine.GetComponent <DrillerCarrier>().GetOwner().AlterNeptunium(-1); } return(EventSuccess); }
/// <summary> /// Applies the specialist's effects to a friendly and enemy combatable. /// </summary> /// <param name="state">The game state</param> /// <param name="friendly">The friendly combatable to effect</param> /// <param name="enemy">The enemy combatable to effect</param> public void ApplyEffect(GameState.GameState state, Entity friendly, Entity enemy) { foreach (var specialistEffect in _specialistEffects) { var effect = (SpecialistEffect)specialistEffect; effect.GetForwardEffectDeltas(state, friendly, enemy); } }
/// <summary> /// Reverses a specialist effect to a friendly and enemy combatable /// </summary> /// <param name="state">Gamestate</param> /// <param name="friendly">The friendly combatable to reverse effects to</param> /// <param name="enemy">The enemy combatable to reverse effects to</param> public void UndoEffect(GameState.GameState state, Entity friendly, Entity enemy) { foreach (var specialistEffect in this._specialistEffects) { var effect = (SpecialistEffect)specialistEffect; effect.GetBackwardEffectDeltas(state, friendly, enemy); } }
protected List <IEntity> GetEffectTargets(GameState.GameState state, Entity friendly, Entity enemy) { List <IEntity> targets = new List <IEntity>(); // Filter based on the trigger range first switch (configuration.EffectTriggerRange) { case EffectTriggerRange.Self: targets.Add(friendly); targets.Add(enemy); break; case EffectTriggerRange.Local: targets.Add(friendly); targets.Add(enemy); break; case EffectTriggerRange.ConstantRange: // TODO: get all ICombatable within range of friendly. break; case EffectTriggerRange.Global: targets.AddRange(state.GetAllGameObjects()); break; case EffectTriggerRange.LocationVisionRange: // TODO: Get all ICombatable within outpost's vision. break; case EffectTriggerRange.PlayerVisionRange: // TODO: Get all ICombatable within player's vision break; } // Filter based on the target switch (configuration.EffectTarget) { case EffectTarget.All: break; case EffectTarget.BothCombatParticipants: break; case EffectTarget.Enemy: targets = targets.FindAll(x => x.GetComponent <DrillerCarrier>().GetOwner() != friendly.GetComponent <DrillerCarrier>().GetOwner()); break; case EffectTarget.Friendly: targets = targets.FindAll(x => x.GetComponent <DrillerCarrier>().GetOwner() == friendly.GetComponent <DrillerCarrier>().GetOwner()); break; case EffectTarget.NoTarget: targets.RemoveAll(x => true); break; } return(targets); }
public override bool BackwardAction(TimeMachine timeMachine, GameState.GameState state) { if (EventSuccess) { _producingFactory.GetComponent <DrillerCarrier>().RemoveDrillers(_productionAmount); return(true); } return(false); }
/// <summary> /// Determine the value of the backward effect to apply. If the effect is a scaling effect, the effect should /// follow the formula start = end / effectValue. If no scaling is to be applied, the effect should follow the formula /// start = end - effectValue. /// </summary> /// <param name="state">The gamestate</param> /// <param name="endValue">The ending value to revert change for</param> /// <param name="friendly">The friendly participant. Null if none.</param> /// <param name="enemy">The enemy participant. Null if none.</param> /// <returns></returns> public float GetBackwardsEffectDelta(GameState.GameState state, int endValue, Entity friendly, Entity enemy) { if (configuration.EffectScale == null) { return(-1 * configuration.Value); } // Difference between end value and the result. return(endValue - (configuration.EffectScale.GetEffectScalar(state, friendly, enemy) / configuration.Value)); }
/// <summary> /// Determine the value of the forward effect to apply. If the effect is a scaling effect, the effect should /// follow the formula end = start * effectValue. If no scaling is to be applied, the effect should follow the formula /// end = start + effectValue. /// </summary> /// <param name="state">Gamestate</param> /// <param name="startValue">The starting value before the effect is applied.</param> /// <param name="friendly">The friendly participant. Null if none.</param> /// <param name="enemy">The enemy participant. Null if none.</param> /// <returns></returns> private float GetForwardEffectDelta(GameState.GameState state, int startValue, Entity friendly, Entity enemy) { if (configuration.EffectScale == null) { return(configuration.Value); } // difference between result & start value if scaling. return(startValue - (configuration.Value * configuration.EffectScale.GetEffectScalar(state, friendly, enemy))); }
public override bool BackwardAction(TimeMachine timeMachine, GameState.GameState state) { if (EventSuccess) { ShieldManager shieldManager = state.GetEntity(GetEventData().SourceId).GetComponent <ShieldManager>(); shieldManager.ToggleShield(); } return(EventSuccess); }
/// <summary> /// Performs the reverse action of the driller combat to undo. /// </summary> /// <returns>if the event was reversed</returns> public bool BackwardAction(TimeMachine timeMachine, GameState.GameState state) { if (_eventSuccess) { // Restore driller counts. _combatant1.GetComponent <DrillerCarrier>().SetDrillerCount(_preCombatDrillers1); _combatant2.GetComponent <DrillerCarrier>().SetDrillerCount(_preCombatDrillers2); } return(_eventSuccess); }
public override bool BackwardAction(TimeMachine timeMachine, GameState.GameState state) { if (EventSuccess) { var drillerCarrier = _drilledMine.GetComponent <DrillerCarrier>(); state.ReplaceOutpost(_drilledMine, _original); drillerCarrier.GetOwner().AlterMinesDrilled(-1); drillerCarrier.AddDrillers(drillerCarrier.GetOwner().GetRequiredDrillersToMine()); } return(EventSuccess); }
/// <summary> /// Validates an ICombatable /// </summary> /// <param name="state">The gamestate</param> /// <param name="combatable">The ICombatable to validate</param> /// <returns></returns> public static bool ValidateICombatable(GameState.GameState state, Entity combatable) { if (combatable is Outpost) { return(ValidateOutpost(state, (Outpost)combatable)); } else if (combatable is Sub) { return(ValidateSub(state, (Sub)combatable)); } return(false); }
/// <summary> /// Undoes the sub's arrival /// </summary> /// <returns>If the event was undone</returns> public override bool BackwardAction(TimeMachine timeMachine, GameState.GameState state) { if (EventSuccess) { _outpost.GetComponent <DrillerCarrier>().RemoveDrillers(_arrivingSub.GetComponent <DrillerCarrier>().GetDrillerCount()); _outpost.GetComponent <SpecialistManager>() .RemoveSpecialists(_arrivingSub.GetComponent <SpecialistManager>().GetSpecialists()); state.AddSub(this._arrivingSub); return(true); } return(false); }
public override bool BackwardAction(TimeMachine timeMachine, GameState.GameState state) { if (EventSuccess) { // perform actions in reverse for (int i = _actions.Count - 1; i >= 0; i--) { this._actions[i].BackwardAction(timeMachine, state); } } return(this.EventSuccess); }
public void UpdateView(GameState.GameState gameState) { playerInfo.text = " "; for (int i = 0; i < gameState.playerList.players.Length; i++) { PlayerData pd = gameState.playerList.players[i]; playerInfo.text += "ID: " + pd.ID.ToString() + " " + pd.nickname + " S_ID:" + pd.networkID + " SLOT: " + (pd.slotTaken ? "TAKEN " : "EMPTY ") + "LOAD: " + (pd.loadState.ToString("g")) + " TYPE: " + (pd.type.ToString("g")) + "\n"; } playerInfo.text += "\nMY ID: " + gameState.playerList.GetClientData().ID + " " + gameState.playerList.GetClientData().nickname + "\n\nPress 'S' to swap with next slot."; this.gameState = gameState; }
/// <summary> /// Performs the backwards event /// </summary> public override bool BackwardAction(TimeMachine timeMachine, GameState.GameState state) { if (this.EventSuccess) { state.GetEntity(GetEventData().SourceId).GetComponent <SubLauncher>().UndoLaunch(state, this); foreach (GameEvent e in _combatEvents) { timeMachine.RemoveEvent(e); } _combatEvents.Clear(); } return(this.EventSuccess); }
/// <summary> /// Perfoms a friendly sub arrival /// </summary> /// <returns>If the event was successful</returns> public override bool ForwardAction(TimeMachine timeMachine, GameState.GameState state) { if (state.SubExists(_arrivingSub) && state.OutpostExists(_outpost)) { _outpost.GetComponent <DrillerCarrier>().AddDrillers(_arrivingSub.GetComponent <DrillerCarrier>().GetDrillerCount()); _outpost.GetComponent <SpecialistManager>().AddSpecialists(_arrivingSub.GetComponent <SpecialistManager>().GetSpecialists()); state.RemoveSub(_arrivingSub); EventSuccess = true; } else { EventSuccess = false; } return(EventSuccess); }
public override bool ForwardAction(TimeMachine timeMachine, GameState.GameState state) { if (!_mine.GetComponent <DrillerCarrier>().GetOwner().IsEliminated() && state.GetOutposts().Contains(_mine) && !_mine.GetComponent <DrillerCarrier>().IsDestroyed()) { _mine.GetComponent <DrillerCarrier>().GetOwner().AlterNeptunium(1); this._nextProduction = new NeptuniumProductionEvent(_mine, GetOccursAt().Advance(Mine.TICKS_PER_PRODUCTION_PER_MINE / state.GetPlayerOutposts(_mine.GetComponent <DrillerCarrier>().GetOwner()).Count)); timeMachine.AddEvent(this._nextProduction); EventSuccess = true; } else { EventSuccess = false; } return(EventSuccess); }
void Run() { updaterate = AppConfig.Instance.updaterate; tickrate = AppConfig.Instance.tickrate; cmdrate = AppConfig.Instance.cmdrate; snapshotOverTick = (uint)Mathf.FloorToInt(updaterate / tickrate); Singletons.Add <InputManager>(); Singletons.Add <SyncManagerClient>(); Singletons.Add <PlayerManagerClient>(); netlayer = new UdpConnector(); mGameState = new GameState.Init(); Time.fixedDeltaTime = tickrate; mGameState.Start(); }
public override bool ForwardAction(TimeMachine timeMachine, GameState.GameState state) { ShieldManager shieldManager = state.GetEntity(GetEventData().SourceId).GetComponent <ShieldManager>(); DrillerCarrier drillerCarrier = state.GetEntity(GetEventData().SourceId).GetComponent <DrillerCarrier>(); if (shieldManager != null && !drillerCarrier.GetOwner().IsEliminated()) { shieldManager.ToggleShield(); EventSuccess = true; } else { EventSuccess = false; } return(EventSuccess); }
/// <summary> /// Performs driller combat between two subs /// </summary> /// <returns>If the event was succesfull</returns> public bool ForwardAction(TimeMachine timeMachine, GameState.GameState state) { if (Validator.ValidateICombatable(state, _combatant1) && Validator.ValidateICombatable(state, _combatant2)) { _preCombatDrillers1 = _combatant1.GetComponent <DrillerCarrier>().GetDrillerCount(); _preCombatDrillers2 = _combatant2.GetComponent <DrillerCarrier>().GetDrillerCount(); _combatant1.GetComponent <DrillerCarrier>().RemoveDrillers(_preCombatDrillers2); _combatant2.GetComponent <DrillerCarrier>().RemoveDrillers(_preCombatDrillers1); this._eventSuccess = true; } else { this._eventSuccess = false; } return(this._eventSuccess); }
public void HandleData(byte[] data) { string datastr = System.Text.Encoding.ASCII.GetString(data).Trim('\0'); serializedGameState += datastr; if (gameState == null) { if (serializedGameState.EndsWith(MultiplayerDataSettings.endChar.ToString())) { gameState = GameStateLoader.Deserialize(serializedGameState.Replace("$", "")); } } else { overheardData += datastr; } }
public ResetRectangle(RectangleShape rectangle, GameState.GameState gameState) { Rectangle = rectangle; var texture = new Texture(Images[gameState]) { Smooth = true }; EmojiSprite = new Sprite(texture) { Position = Rectangle.Position, Origin = Rectangle.Origin }; // the texture is a square var scale = Rectangle.Size / EmojiSprite.TextureRect.Height; EmojiSprite.Scale = scale; }
/// <summary> /// Performs the forward event /// </summary> public override bool ForwardAction(TimeMachine timeMachine, GameState.GameState state) { this._launchedSub = state.GetEntity(GetEventData().SourceId).GetComponent <SubLauncher>().LaunchSub(state, this); if (_launchedSub != null && !_launchedSub.GetComponent <DrillerCarrier>().GetOwner().IsEliminated()) { _combatEvents.AddRange(CreateCombatEvents(_launchedSub, state)); foreach (GameEvent e in _combatEvents) { timeMachine.AddEvent(e); } this.EventSuccess = true; } else { this.EventSuccess = false; } return(this.EventSuccess); }
public bool ForwardAction(TimeMachine timeMachine, GameState.GameState state) { if (_isTie) { // TODO: Handle tie. return(false); } if (_loser is Sub) { // Cleanup the sub. if (_loser.GetComponent <SpecialistManager>().GetSpecialistCount() > 0) { _loser.GetComponent <SpecialistManager>().CaptureAll(); ((Sub)_loser).GetComponent <DrillerCarrier>().SetCaptured(true); } else { // Remove the sub state.RemoveSub((Sub)_loser); } } if (_loser is Outpost) { // Transfer Ownership and give drillers. _loser.GetComponent <DrillerCarrier>().SetOwner(_winner.GetComponent <DrillerCarrier>().GetOwner()); // Remove the winning sub and make it arrive at the outpost. _loser.GetComponent <DrillerCarrier>().SetDrillerCount(0); _loser.GetComponent <DrillerCarrier>().AddDrillers(_winner.GetComponent <DrillerCarrier>().GetDrillerCount()); // Transfer any specialists to the outpost. _loser.GetComponent <SpecialistManager>().CaptureAll(); _winner.GetComponent <SpecialistManager>().TransferSpecialistsTo(_loser.GetComponent <SpecialistManager>()); // Remove the incoming sub. state.RemoveSub((Sub)_winner); } this._isSuccess = true; return(_isSuccess); }
public override bool ForwardAction(TimeMachine timemachine, GameState.GameState state) { _productionAmount = this._producingFactory.GetDrillerProduction(state); if (state.OutpostExists(_producingFactory) && this._productionAmount > 0 && !this._producingFactory.GetComponent <DrillerCarrier>().IsDestroyed()) { _producingFactory.GetComponent <DrillerCarrier>().AddDrillers(this._productionAmount); EventSuccess = true; if (_nextProduction == null) { _nextProduction = new FactoryProduction(_producingFactory, base.GetOccursAt().Advance(this._producingFactory.GetTicksPerProduction())); timemachine.AddEvent(this._nextProduction); } } else { EventSuccess = false; } return(EventSuccess); }