internal void RenderReplayTick(Tick tick, CombatComponent comp) { // Reserve the back buffer for updates. GameImageSource.Lock(); unsafe { int pBackBuffer = (int)GameImageSource.BackBuffer; // // Update map with all active components, players etc // using (GameImageSource.GetBitmapContext()) { foreach (var updatedPlayer in tick.GetUpdatedPlayers()) { DrawEntity(updatedPlayer); } if (comp != null && comp.links.Count != 0) { foreach (var link in comp.links) { DrawLink(link); } } } } // Release the back buffer and make it available for display. GameImageSource.Unlock(); }
private void Awake() { player = GameObject.FindGameObjectWithTag("Player"); Assert.IsNotNull(player, "Failed to locate GameObject with tag <b>Player</b>"); agent = GetComponent <NavMeshAgent>(); Assert.IsNotNull(agent, "Failed to locate <b>NavMeshAgent</b> on Enemy GameObject"); stateMachine = GetComponent <ChickenStateMachine>(); Assert.IsNotNull(stateMachine, "Failed to locate <b>ChickenStateMachine.cs</b> on Enemy GameObject"); perceptionScript = GetComponent <AIPerception>(); Assert.IsNotNull(perceptionScript, "Failed to locate <b>AIPerception.cs</b> on Enemy GameObject"); playerLightComponent = player.GetComponent <LightComponent>(); Assert.IsNotNull(playerLightComponent, "Failed to locate <b>LightComponent.cs</b> on Player GameObject"); playerCombatComponent = player.GetComponent <CombatComponent>(); Assert.IsNotNull(playerCombatComponent, "Failed to locate <b>CombatComponent.cs</b> on Player GameObject"); lightBombs = GameObject.FindGameObjectsWithTag("LightBomb"); Assert.IsNotNull(lightBombs, "Failed to locate <b>LightBombs</b> in array check in Enemy GameObject"); gameManager = player.GetComponent <GameManagerComponent>(); Assert.IsNotNull(gameManager, "Failed to locate <b>GameManagerComponent.cs</b> on Player GameObject"); world = GameObject.FindGameObjectWithTag("World"); Assert.IsNotNull(world, "Failed to locate <b>World</b> under Main scene in hierarchy"); worldSystem = world.GetComponent <World>(); Assert.IsNotNull(worldSystem, "Failed to locate <b>World.cs</b> on World GameObject"); originalWaitTime = waitTime; originalHuntTime = huntTime; originalAttackCooldown = attackCooldown; originalWalkSpeed = agent.speed; originalChargeSpeed = chargeSpeed; }
internal void StartConstruction(Level Level, BuildingToMove Xy) { Building GameObject = new Building(this.BuildingData, Level); CombatComponent CombatComponent = GameObject.CombatComponent; GameObject.SetUpgradeLevel(-1); GameObject.Position.X = Xy.X << 9; GameObject.Position.Y = Xy.Y << 9; if (CombatComponent != null) { CombatComponent.WallI = Level.Player.WallGroupId; } else { Logging.Error(this.GetType(), "CombatComponent should not be null when buying multiple wall!"); } Level.WorkerManagerV2.AllocateWorker(GameObject); if (this.BuildingData.GetBuildTime(0) <= 0) { GameObject.FinishConstruction(); } else { GameObject.ConstructionTimer = new Timer(); GameObject.ConstructionTimer.StartTimer(Level.Player.LastTick, this.BuildingData.GetBuildTime(0)); } Level.GameObjectManager.AddGameObject(GameObject); }
public override void Initialize(Transform[] objects) { // list because I don't know size here List <Filter> tmpFilters = new List <Filter>(); int index = 0; for (int i = 0; i < objects.Length; i++) { // check performance EnemyComponent ec = objects[i].GetComponent <EnemyComponent>(); CombatComponent cc = objects[i].GetComponent <CombatComponent>(); HealthComponent hc = objects[i].GetComponent <HealthComponent>(); if (cc && hc) { tmpFilters.Add(new Filter(index, objects[i].gameObject, ec, cc, hc)); } } filters = tmpFilters.ToArray(); environmentComponent = GetComponentInChildren <EnvironmentComponent>(); transportableComponent = GetComponentInChildren <CartComponent>(); inputComponent = GetComponentInChildren <InputComponent>(); }
private void Awake() { movement = GetComponent <CharacterMovement>(); combat = GetComponent <CombatComponent>(); distanceFalloffExponent = Mathf.Max(0, distanceFalloffExponent); equipment = GetComponent <CharacterEquipment>(); }
private void InitializeComponents() { anim = GetComponent <Animator>(); rb = GetComponent <Rigidbody2D>(); //collider = GetComponent<Collider2D>(); stateInfo = GetComponent <EntityState>(); combatComponent = GetComponent <CombatComponent>(); enemyController = GetComponent <EnemyController>(); }
internal override void Execute() { Level Level = this.Device.GameMode.Level; GameObject GameObject = Level.GameObjectManager.Filter.GetGameObjectById(this.BuildingID); if (GameObject != null) { if (GameObject is Building) { Building Building = (Building)GameObject; CombatComponent CombatComponent = Building.CombatComponent; if (CombatComponent != null) { if (CombatComponent.AltAttackMode) { CombatComponent.AttackMode = !CombatComponent.AttackMode; CombatComponent.AttackModeDraft = !CombatComponent.AttackModeDraft; } } else { Logging.Error(this.GetType(), "Unable to change the weapon mode. The CombatComponent for the game object is null."); } } else if (GameObject is Trap) { Trap Trap = (Trap)GameObject; CombatComponent CombatComponent = Trap.CombatComponent; if (CombatComponent != null) { if (CombatComponent.AltTrapAttackMode) { CombatComponent.AirMode = !CombatComponent.AirMode; CombatComponent.AirModeDraft = !CombatComponent.AirModeDraft; } } else { Logging.Error(this.GetType(), "Unable to change the trap mode. The CombatComponent for the game object is null."); } } else { Logging.Error(this.GetType(), "Unable to change the weapon mode. Unable to determine game object"); } } else { Logging.Error(this.GetType(), "Unable to change the weapon mode. The game object is null."); } }
internal override void Execute() { Level Level = this.Device.GameMode.Level; GameObject GameObject = Level.GameObjectManager.Filter.GetGameObjectById(this.BuildingID); if (GameObject != null) { if (GameObject is Building) { Building Building = (Building)GameObject; CombatComponent CombatComponent = Building.CombatComponent; if (CombatComponent != null) { if (CombatComponent.AimRotateStep) { CombatComponent.AimAngle = CombatComponent.AimAngle == 360 ? 45 : CombatComponent.AimAngle + 45; CombatComponent.AimAngleDraft = CombatComponent.AimAngleDraft == 360 ? 45 : CombatComponent.AimAngleDraft + 45; } } else { Logging.Error(this.GetType(), "Unable to change the weapon heading. The CombatComponent for the game object is null."); } } else if (GameObject is Trap) { Trap Trap = (Trap)GameObject; CombatComponent CombatComponent = Trap.CombatComponent; if (CombatComponent != null) { if (CombatComponent.AltDirectionMode) { CombatComponent.TrapDirection = CombatComponent.TrapDirection == 3 ? 0 : ++CombatComponent.TrapDirection; CombatComponent.TrapDirectionDraft = CombatComponent.TrapDirectionDraft == 3 ? 0 : ++CombatComponent.TrapDirectionDraft; } } else { Logging.Error(this.GetType(), "Unable to change the trap heading. The CombatComponent for the game object is null."); } } else { Logging.Error(this.GetType(), "Unable to change the weapon heading. Unable to determine game object"); } } else { Logging.Error(this.GetType(), "Unable to change the weapon heading. The game object is null."); } }
public override void Initialize(Transform[] objects) { worldStateComponent = GetComponentInChildren <WorldStateComponent>(); // list because I don't know size here List <Filter> tmpFilters = new List <Filter>(); int index = 0; for (int i = 0; i < objects.Length; i++) { // check performance EnemyComponent ec = objects[i].GetComponent <EnemyComponent>(); CombatComponent cc = objects[i].GetComponent <CombatComponent>(); HealthComponent hc = objects[i].GetComponent <HealthComponent>(); GOAPComponent aic = objects[i].GetComponent <GOAPComponent>(); if (cc && hc && ec && aic) { tmpFilters.Add(new Filter(index, objects[i].gameObject, ec, cc, hc, aic)); aic.stateMachine = new FSM(); aic.availableActions = new HashSet <GOAPAction>(); aic.currentActions = new Queue <GOAPAction>(); GOAPAction[] actions = aic.gameObject.GetComponents <GOAPAction>(); foreach (GOAPAction action in actions) { aic.availableActions.Add(action); action.constantTarget = worldStateComponent.gameObject; } CreateIdleState(aic); CreateMoveToState(aic); CreatePerformActionState(aic); aic.stateMachine.pushState(aic.idleState); } } filters = tmpFilters.ToArray(); planner = new GOAPPlanner(); //currentWorldState = new HashSet<KeyValuePair<string, object>>(); KeyValuePair <string, object> playerDmgState = new KeyValuePair <string, object>("damagePlayer", false); KeyValuePair <string, object> playerStalkState = new KeyValuePair <string, object>("stalkPlayer", false); worldStateComponent.worldState.Add(playerLitState); worldStateComponent.worldState.Add(playerDmgState); worldStateComponent.worldState.Add(playerStalkState); /*currentWorldState.Add(playerLitState); * currentWorldState.Add(playerDmgState); * currentWorldState.Add(playerStalkState);*/ }
public Filter(int id, GameObject go, CombatComponent cc, InputComponent ic ) { this.id = id; gameObject = go; combatComponent = cc; inputComponent = ic; }
public Filter(int id, GameObject go, CartComponent tc, CombatComponent cc ) { this.id = id; gameObject = go; transportableComponent = tc; combatComponent = cc; }
public override void Tick(float deltaTime) { for (int i = 0; i < filters.Length; i++) { // cache variables Filter filter = filters[i]; EnemyComponent enemyComp = filter.enemyComponent; CombatComponent combComp = filter.combatComponent; HealthComponent healthComp = filter.healthComponent; // ----- logic ----- if (gameOver) { if (Input.GetKeyDown(KeyCode.F)) { Restart(); } alpha += deltaTime * 0.3f; } float dst = Vector3.Distance(filter.gameObject.transform.position, inputComponent.transform.position); if (dst > enemyComp.aggroRange) { enemyComp.agent.ResetPath(); return; } if (inputComponent.avoidPlayer) { enemyComp.isPursuingTransportable = false; //EngageTransform(enemyComp, returnGO.transform); } if (enemyComp.isActive) { if (!inputComponent.avoidPlayer) { //EngageTransform(enemyComp, inputComponent.gameObject.transform); } } /*float remainingDist = Vector3.Distance(enemyComp.transform.position, transportableComponent.transform.position); * if (enemyComp.agent.hasPath && remainingDist < 2f) * { * gameOver = true; * loseTXT.gameObject.SetActive(true); * blockIMG.gameObject.SetActive(true); * blockIMG.color = new Color(blockIMG.color.r, blockIMG.color.g, blockIMG.color.b, alpha); * }*/ } }
public Filter(int id, GameObject go, EnemyComponent ec, CombatComponent cc, HealthComponent hc ) { this.id = id; gameObject = go; enemyComponent = ec; combatComponent = cc; healthComponent = hc; }
private void Start() { dir = DirectionEnum.Bottom; spriteManager.init(gameObject.GetComponent <SpriteRenderer>(), dir); path = null; player = GameObject.FindGameObjectWithTag("Player"); CircleCollider2D circle = gameObject.GetComponent <CircleCollider2D>(); combatComponent = gameObject.GetComponent <CombatComponent>(); if (circle != null) { circle.radius = maxMovementDist; circle.isTrigger = true; } }
private void OnTriggerEnter2D(Collider2D collision) { if (!isDead) { if (collision.tag == "Weapon" && collision != ownCollider) { CombatComponent cbc = collision.gameObject.transform.parent.parent.GetComponent <CombatComponent>(); if (cbc != null && cbc.AttckUID != LastAttckUIDReceive) { LastAttckUIDReceive = cbc.AttckUID; if (takeDamage(cbc.damage)) { isDead = true; } } } } }
public void Initialize() { if (!initialized) { return; } Transform[] worldObjects = GetComponentsInChildren <Transform>(); inputSystem.Initialize(worldObjects); InputComponent inpC = playerObject.GetComponent <InputComponent>(); HealthComponent healthC = playerObject.GetComponent <HealthComponent>(); InteractorComponent intC = playerObject.GetComponent <InteractorComponent>(); MovementComponent moveC = playerObject.GetComponent <MovementComponent>(); InventoryComponent invC = playerObject.GetComponent <InventoryComponent>(); GameManagerComponent gmC = playerObject.GetComponent <GameManagerComponent>(); AnimationComponent animC = playerObject.GetComponent <AnimationComponent>(); PlayerStoryComponent storyBeatC = playerObject.GetComponent <PlayerStoryComponent>(); PlayerEventComponent eventC = playerObject.GetComponent <PlayerEventComponent>(); GatheringComponent gatC = playerObject.GetComponent <GatheringComponent>(); UIComponent uiC = playerObject.GetComponent <UIComponent>(); NavMeshComponent nmC = playerObject.GetComponent <NavMeshComponent>(); LightComponent lC = playerObject.GetComponent <LightComponent>(); VFXComponent vfxC = playerObject.GetComponent <VFXComponent>(); CombatComponent cC = playerObject.GetComponent <CombatComponent>(); AudioComponent aC = playerObject.GetComponent <AudioComponent>(); ConditionsComponent conC = playerObject.GetComponent <ConditionsComponent>(); PlayerFilter pf = new PlayerFilter( playerObject, inpC, healthC, intC, moveC, invC, gmC, animC, storyBeatC, eventC, gatC, uiC, nmC, lC, vfxC, cC, aC, conC); sbs = GetComponent <StoryBeatSystem>(); for (int i = 0; i < systems.Length; i++) { systems[i].player = pf; systems[i].Initialize(worldObjects); systems[i].SetupInputComponent(inputSystem.inputComponent); } }
public override void Tick(float deltaTime) { for (int i = 0; i < filters.Length; i++) { // cache variables Filter filter = filters[i]; CartComponent transComp = filter.transportableComponent; CombatComponent combComp = filter.combatComponent; // ----- logic ----- /*if (transComp.isTraveling) * { * transComp.ConsumeFuel(deltaTime); * transComp.agent.Move(transComp.GetOwnerGO().transform.TransformDirection(transform.forward) * transComp.travelSpeed * deltaTime); * }*/ } }
public override void Initialize(Transform[] objects) { // list because I don't know size here List <Filter> tmpFilters = new List <Filter>(); int index = 0; for (int i = 0; i < objects.Length; i++) { // check performance CartComponent tc = objects[i].GetComponent <CartComponent>(); CombatComponent cc = objects[i].GetComponent <CombatComponent>(); if (tc) { tmpFilters.Add(new Filter(index, objects[i].gameObject, tc, cc)); } } filters = tmpFilters.ToArray(); }
private void Start() { sw = System.Diagnostics.Stopwatch.StartNew(); previousLevel = 0; speed = initialSpeed; runSpeed = initialRunSpeed; dir = DirectionEnum.Bottom; spriteManager.init(gameObject.GetComponent <SpriteRenderer>(), dir); spriteManager.changeLycanthropieLevel(0); bloodLustComponent = gameObject.GetComponent <BloodLust>(); lycanthropyComponent = gameObject.GetComponent <Lycanthropy>(); combatComponent = gameObject.GetComponent <CombatComponent>(); rb = gameObject.GetComponent <Rigidbody2D>(); lycanthropyComponent.startGame(bloodLustComponent); bloodLustComponent.startGame(); Utils.Init(); cam = FindObjectOfType <Cinemachine.CinemachineVirtualCamera>(); cam.Follow = transform; FindObjectOfType <Cinemachine.CinemachineConfiner>().m_BoundingShape2D = confinedCollider; }
public override void Tick(float deltaTime) { //ToggleLightState(); for (int i = 0; i < filters.Length; i++) { Filter filter = filters[i]; EnemyComponent enemyComp = filter.enemyComponent; CombatComponent combComp = filter.combatComponent; HealthComponent healthComp = filter.healthComponent; GOAPComponent aiComp = filter.aiComponent; aiComp.stateMachine.Update(aiComp.gameObject); if (!aiComp.HasMaxEnergy()) { aiComp.RegenerateEnergy(deltaTime); } } }
public PlayerFilter( GameObject go, InputComponent inputC, HealthComponent healthC, InteractorComponent interactC, MovementComponent moveC, InventoryComponent inventoryC, GameManagerComponent gmc, AnimationComponent animC, PlayerStoryComponent psC, PlayerEventComponent peC, GatheringComponent gC, UIComponent uiC, NavMeshComponent nmC, LightComponent lC, VFXComponent vfxC, CombatComponent cC, AudioComponent aC, ConditionsComponent conC) { this.go = go; inputComponent = inputC; healthComponent = healthC; interactorComponent = interactC; movementComponent = moveC; inventoryComponent = inventoryC; gameManagerComponent = gmc; animationComponent = animC; playerStoryComponent = psC; eventComponent = peC; gatheringComponent = gC; uiComponent = uiC; navMeshComponent = nmC; lightComponent = lC; vfxComponent = vfxC; combatComponent = cC; audioComponent = aC; conditionsComponent = conC; }
/// <summary> /// Serialize this component into an outgoing message. /// </summary> /// <param name="msg"></param> public void Serialize(NetOutgoingMessage msg) { // Mothership msg.Write(Team.Mothership.Id); msg.Write(Team.Mothership.Resources.Value); msg.Write(Team.Mothership.Position.Position.X); msg.Write(Team.Mothership.Position.Position.Y); // Team members msg.Write(Team.MemberCount); for (int i = 0; i < Team.MemberCount; i++) { msg.Write(Team.Members[i].Id); msg.Write(Team.Members[i].Resources.Value); msg.Write(Team.Members[i].Position.Position.X); msg.Write(Team.Members[i].Position.Position.Y); CombatComponent combat = (CombatComponent)Team.Members[i] .GetComponent(ComponentSystemId.CombatSystem); combat.Serialize(msg); } }
/// <summary> /// /// </summary> /// <param name="obj"></param> private void Execute_PlayReplay(object obj) { Console.WriteLine("Play Match"); if (IsPaused) { _Busy.Set(); IsPaused = false; return; } else { Console.WriteLine("Game already running"); } if (Replay == null) { return; } _Replaybw.DoWork += (sender, args) => { int last_tickid = 0; foreach (var tuple in Replay.GetReplayData()) { if (_Replaybw.IsBusy) // Give _busy a chance to reset backgroundworker { _Busy.WaitOne(); } Tick tick = tuple.Key; // Tick is containing the game data (player positions, values of health, facing etc) CombatComponent comp = tuple.Value; // Comp is containing the encounter detection data (links) TickID = tick.tick_id; // Update TickID property of the view if (last_tickid == 0) { last_tickid = tick.tick_id; } int dt = tick.tick_id - last_tickid; int passedTime = (int)(dt * 1000 / Replay.Tickrate); Time += passedTime; // Update Time property of the view //Jump out of backgroundworker to render a tick of the game Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => { Renderer.RenderReplayTick(tick, comp); })); //Wait to render next frame Thread.Sleep(passedTime); last_tickid = tick.tick_id; } }; _Replaybw.RunWorkerAsync(); _Replaybw.RunWorkerCompleted += (sender, args) => { if (args.Error != null) { MessageBox.Show(args.Error.ToString()); } }; }
// Using Start instead of Awake to ensure Player is initialized first public void Start() { inputDelay = new InputDelay(); playerMovement = player.GetComponent <PlayerController>().GetMovement(); playerCombat = player.GetComponent <PlayerController>().Combat(); }
// for gizmos //private Projectile[] debugProjectiles; public override void Tick(float deltaTime) { for (int i = 0; i < filters.Length; i++) { // cache variables Filter filter = filters[i]; CombatComponent combComp = filter.combatComponent; InputComponent inputComp = filter.inputComponent; // ----- logic ----- if (inputComp.xButtonDown || Input.GetKeyDown(KeyCode.X)) { PerformTorchSwing(combComp); } /*if (combComp.projectiles != null) * { * MoveProjectiles(combComp.projectiles, deltaTime); * HandleProjectileCollision(filter); * } * * if (combComp.isEngagedInCombat) * { * if (inputComp.GetMouseButtonDown(0)) * { * RaycastHit hit; * inputComp.GetMouseWorldLocation(out hit); * HealthComponent hc = hit.transform.GetComponentInParent<HealthComponent>(); * * if (hc) * { * LaunchProjectile(hc, combComp); * } * } * } * * debugProjectiles = combComp.projectiles;*/ } LightComponent lc = player.lightComponent; HealthComponent hc = player.healthComponent; /* * if (Input.GetKeyDown(KeyCode.H)) * { * hc.RestoreGranularDamageOverTime(100f, 5f, true); * } * else if (Input.GetKeyDown(KeyCode.L)) * { * hc.TakeGranularDamageOverTime(50f, 1f, true); * }*/ if (!hc.isHealing) { if (hc.isTakingDamage) { if (hc.healthAlterDuration > hc.currentAlterTime) { float healthPercentage = hc.currentGranularHealth / hc.maxGranularHealth; player.uiComponent.healthIndicator.SetImageFillAmount(hc.currentHealth, healthPercentage); player.healthComponent.TakeGranularDamage(hc.alterTickAmount * deltaTime); hc.currentAlterTime += Time.deltaTime; return; } else { hc.isTakingDamage = false; } } if (lc.nearbyLights.Count == 0 && !lc.IsLightEnabled()) { if (hc.currentGranularHealth > 0) { float healthPercentage = hc.currentGranularHealth / hc.maxGranularHealth; player.uiComponent.healthIndicator.SetImageFillAmount(hc.currentHealth, healthPercentage); player.healthComponent.TakeGranularDamage(hc.darknessGranularHealthDrain * deltaTime); } } else { if (hc.currentGranularHealth <= hc.maxGranularHealth && !player.combatComponent.isRunning) { float healthPercentage = hc.currentGranularHealth / hc.maxGranularHealth; player.uiComponent.healthIndicator.SetImageFillAmount(hc.currentHealth, healthPercentage); player.healthComponent.RestoreGranularDamage(hc.granularHealthRestorationAmount * deltaTime); } } } else { if (hc.healthAlterDuration > hc.currentAlterTime && hc.currentGranularHealth <= hc.maxGranularHealth) { float healthPercentage = hc.currentGranularHealth / hc.maxGranularHealth; player.uiComponent.healthIndicator.SetImageFillAmount(hc.currentHealth, healthPercentage); player.healthComponent.RestoreGranularDamage(hc.alterTickAmount * deltaTime); hc.currentAlterTime += Time.deltaTime; } else { hc.isHealing = false; } } }
private void PerformTorchSwing(CombatComponent cc) { player.animationComponent.OnPlayAttackAnimation(); player.movementComponent.movementAllowed = false; }
public virtual void Execute(CombatComponent go) { this.Log(go); }
protected virtual void Log(CombatComponent go) { //log basic command to console Debug.Log($"{this.Log()} executed on {go.ToString()}"); }
public override void Execute(CombatComponent go) { go.DamagedBy(damage); base.Execute(go); }
public override void Execute(CombatComponent go) { go.HealedBy(health); base.Execute(go); }