public void AddModifier(MovementModifier mod) { if (!movementModifiers.Contains(mod)) { movementModifiers.Add(mod); } }
public void RemoveModifier(MovementModifier mod) { if (movementModifiers.Contains(mod)) { Log.Info("Remove Mod"); movementModifiers.Remove(mod); } }
private void GenerateColliderForTile(int x, int y, MovementModifier modifier, bool solid) { Vector2 tileCenter = GetLogicalCenterOfTile(x, y); ColliderWithModifier tileCollider = new ColliderWithModifier(modifier, solid) { Position = tileCenter, Size = new Vector2(32, 32) }; }
public void Deactivate() { if (active) { thisObj.SetActive(false); mod = null; rolling = false; active = false; } }
public void TestApplyModifier_SwampWalk() { MovementModifier modifier = MovementModifier.SwampWalk; Vector4 speedLimits = new Vector4(1f, 1f, 1f, 1f); MethodInfo applyModifier = physicsReflection.GetMethod("ApplyModifier", BindingFlags.NonPublic | BindingFlags.Static); Vector4 result = (Vector4)applyModifier.Invoke(null, new object[] { modifier, speedLimits }); Assert.AreEqual(speedLimits.X, result.X); Assert.AreEqual(modifier.Function(speedLimits.Y, modifier.Value), result.Y); Assert.AreEqual(modifier.Function(speedLimits.Z, modifier.Value), result.Z); Assert.AreEqual(modifier.Function(speedLimits.W, modifier.Value), result.W); }
/// <summary> /// Creates a new tile at the given coordinates and the given textures and creates a collider for it. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="texture"></param> /// <param name="opt"></param> public void SetTileAt(int x, int y, BitmapImage texture, bool solid, MovementModifier modifier = null) { //0 is the top since we go from top left so it has to be mirrored y = 15 - y; Tile tile = new Tile(); GenerateColliderForTile(x, y, modifier, solid); Tiles[x, y] = tile; tile.TilePosition = new Vector2(x, y); tile.ChunkParent = this; tile.Texture = texture; }
/// <summary> /// Sets the tile at the given coordinates in this chunk to the given tile type and registers a collider for it. /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="tileType"></param> /// <param name="imagePath"></param> public void SetTileAt(int x, int y, Tile tile, bool solid, MovementModifier modifier = null) { //0 is the top since we go from top left so it has to be mirrored y = 15 - y; GenerateColliderForTile(x, y, modifier, solid); Tiles[x, y] = tile; tile.TilePosition = new Vector2(x, y); tile.ChunkParent = this; //ChunkCanvas.Children.Add(tile); //Canvas.SetLeft(tile, (x * 32)); //.SetTop(tile, (y * 32)); }
public void ModifySpeed(MovementModifier pModifier) { switch (pModifier) { case MovementModifier.forward: //directionToMove = -1; movementModif = 5f; break; case MovementModifier.backward: //directionToMove = 1; movementModif = -3f; break; case MovementModifier.reset: //directionToMove = 1; movementModif = 0; break; } }
public void Activate(MovementModifier mod, Action modCallback) { if (!active) { thisObj.SetActive(true); this.mod = mod; this.modCallback = modCallback; if (initialRollPosition == Vector3.zero) { initialRollPosition = rollBox.transform.position; } else { rollBox.transform.position = initialRollPosition; } choosingSpace = false; ActivateButtons(); StartCoroutine(StartRoll()); active = true; } }
internal virtual void PostUpgradeModuleChange(int slotID, TechType techType, bool added, Hoverbike instance = null) { if (parentHoverbike == null) { if (instance != null) { Initialise(ref instance); } else { return; } } // My first instinct is always to use switch() in situations like this, but you can't use switch() with non-const types. if (techType == techTypeWaterTravel) { bHasTravelModule = HasTravelModule(); } else if (techType == techTypeHullModule) { parentHoverbike.gameObject.EnsureComponent <HoverbikeStructuralIntegrityModifier>().SetActive(added); } else if (techType == techTypeMobility) { bHasTravelModule = HasTravelModule(); if (GetModuleCount(TechType.HoverbikeJumpModule) < 1) { FieldInfo jump = typeof(Hoverbike).GetField("jumpEnabled", BindingFlags.Instance | BindingFlags.NonPublic); if (jump != null) { jump.SetValue(parentHoverbike, added); } } } else if (techType == techTypeRepair) { bHasSelfRepair = added; } else if (techType == techTypeDurability) { bHasSelfRepair = added; parentHoverbike.gameObject.EnsureComponent <HoverbikeStructuralIntegrityModifier>().SetActive(added); } if (TryGetDefaultFloat("enginePowerConsumption", out float defaultPowerConsumption)) { float effectiveEfficiency = 1f; int priority = 0; //Log.LogDebug($"HoverbikeUpdate.PostUpgradeModuleChange(): applying efficiency modifiers"); //foreach (EfficiencyModifier modifier in efficiencyModifiers) foreach (KeyValuePair <TechType, EfficiencyModifier> modifierPair in efficiencyModifiers) { EfficiencyModifier modifier = modifierPair.Value; //Log.LogDebug($"Using modifier {modifier.ToString()}"); //int moduleCount = GetModuleCount(modifier.techType); int moduleCount = GetModuleCount(modifierPair.Key); if (moduleCount > 0) { moduleCount = Math.Min(moduleCount, modifier.maxUpgrades); // This could've been included as part of the assignment, but this way we only do the Min() call if it's needed. if (modifier.priority > priority) { effectiveEfficiency = modifier.efficiencyMultiplier * moduleCount; priority = modifier.priority; //Log.LogDebug($"Using modifier with higher priority {priority}; effectiveEfficiency now {modifier.efficiencyMultiplier}"); } else if (modifier.priority == priority) { effectiveEfficiency *= modifier.efficiencyMultiplier * moduleCount; } // There is no else. } } float newConsumption = defaultPowerConsumption * effectiveEfficiency; Log.LogDebug($"HoverbikeUpdate.PostUpgradeModuleChange(): changed TechType {techType.AsString()}; found defaultPowerConsumption of {defaultPowerConsumption} and calculated new power consumption of {newConsumption}"); parentHoverbike.enginePowerConsumption = newConsumption; } if (TryGetDefaultFloat(nameof(Hoverbike.forwardAccel), out float defaultForwardAccel) && TryGetDefaultFloat(nameof(Hoverbike.forwardBoostForce), out float defaultBoost) && TryGetDefaultFloat(nameof(Hoverbike.boostCooldown), out float defaultCooldown) && TryGetDefaultFloat(nameof(Hoverbike.jumpCooldown), out float defaultJumpCooldown)) { float speedMult = 1f; float cooldownMult = 1f; int priority = 0; //Log.LogDebug($"HoverbikeUpdate.PostUpgradeModuleChange(): applying movement modifiers"); //foreach (MovementModifierStruct modifier in movementModifiers) foreach (KeyValuePair <TechType, MovementModifier> modifierPair in movementModifiers) { //Log.LogDebug($"Using modifier {modifier.ToString()}"); MovementModifier modifier = modifierPair.Value; int moduleCount = GetModuleCount(modifierPair.Key); if (moduleCount > 0) { moduleCount = Math.Min(moduleCount, modifier.maxUpgrades); if (modifier.priority > priority) { speedMult = modifier.speedModifier * moduleCount; cooldownMult = modifier.cooldownModifier * moduleCount; priority = modifier.priority; //Log.LogDebug($"Using modifier with higher priority {priority}; speedMult now {speedMult}, cooldownMult now {cooldownMult}"); } else if (modifier.priority == priority) { speedMult *= modifier.speedModifier * moduleCount; cooldownMult *= modifier.cooldownModifier * moduleCount; //Log.LogDebug($"Using modifier with equal priority {priority}; speedMult now {speedMult}, cooldownMult now {cooldownMult}"); } // There is no else. } } parentHoverbike.forwardAccel = defaultForwardAccel * speedMult; parentHoverbike.forwardBoostForce = defaultBoost * speedMult; parentHoverbike.boostCooldown = defaultCooldown * cooldownMult; parentHoverbike.jumpCooldown = defaultJumpCooldown * cooldownMult; } }
/// <summary> /// Author: Denis /// Removes a movement modifier to the list /// </summary> /// <param name="Mod"></param> public void RemoveModifier(MovementModifier Mod) => Modifiers.Remove(Mod);
/// <summary> /// Author: Denis /// Adds a movement modifier to the list /// </summary> /// <param name="Mod"></param> public void AddModifier(MovementModifier Mod) => Modifiers.Add(Mod);
public void AddModifier(MovementModifier modifier) { _modifiers.Add(modifier); }
public GameObject RemoveModifier(MovementModifier mod) { modifier = null; return(this.gameObject); }
public GameObject AddModifier(MovementModifier mod) { modifier = mod; return(this.gameObject); }