//Only works serverside: public void DoMeleeDamage(Vector2 dmgPosition, GameObject originator, int dmgAmt) { Vector3Int cellPos = metaTileMap.WorldToCell(dmgPosition); MetaDataNode data = metaDataLayer.Get(cellPos); if (Layer.LayerType == LayerType.Windows) { if (metaTileMap.HasTile(cellPos, LayerType.Windows)) { PlaySoundMessage.SendToAll("GlassHit", dmgPosition, Random.Range(0.9f, 1.1f)); AddWindowDamage(dmgAmt, data, cellPos, dmgPosition); return; } } if (Layer.LayerType == LayerType.Grills) { //Make sure a window is not protecting it first: if (!metaTileMap.HasTile(cellPos, LayerType.Windows)) { if (metaTileMap.HasTile(cellPos, LayerType.Grills)) { PlaySoundMessage.SendToAll("GrillHit", dmgPosition, Random.Range(0.9f, 1.1f)); AddGrillDamage(dmgAmt, data, cellPos, dmgPosition); } } } }
private void DoBulletDamage(BulletBehaviour bullet, Vector3 forceDir, Vector3 hitPos) { forceDir.z = 0; Vector3 bulletHitTarget = hitPos + (forceDir * 0.2f); Vector3Int cellPos = metaTileMap.WorldToCell(Vector3Int.RoundToInt(bulletHitTarget)); MetaDataNode data = metaDataLayer.Get(cellPos); if (Layer.LayerType == LayerType.Windows) { LayerTile getTile = metaTileMap.GetTile(cellPos, LayerType.Windows); if (getTile != null) { //TODO damage amt based off type of bullet AddWindowDamage(bullet.damage, data, cellPos, bulletHitTarget); return; } } if (Layer.LayerType == LayerType.Grills) { //Make sure a window is not protecting it first: if (!metaTileMap.HasTile(cellPos, LayerType.Windows, true)) { if (metaTileMap.HasTile(cellPos, LayerType.Grills, true)) { //TODO damage amt based off type of bullet AddGrillDamage(bullet.damage, data, cellPos, bulletHitTarget); } } } }
private void DoBulletDamage(BulletBehaviour bullet, Vector3 forceDir, Vector3 hitPos) { forceDir.z = 0; Vector3 bulletHitTarget = hitPos + (forceDir * 0.2f); Vector3Int cellPos = metaTileMap.WorldToCell(Vector3Int.RoundToInt(bulletHitTarget)); MetaDataNode data = metaDataLayer.Get(cellPos); if (Layer.LayerType == LayerType.Windows) { LayerTile getTile = metaTileMap.GetTile(cellPos, LayerType.Windows); if (getTile != null) { //TODO damage amt based off type of bullet AddWindowDamage(bullet.damage, data, cellPos, bulletHitTarget, AttackType.Bullet); return; } } if (Layer.LayerType == LayerType.Grills) { //Make sure a window is not protecting it first: if (!metaTileMap.HasTile(cellPos, LayerType.Windows, true)) { if (metaTileMap.HasTile(cellPos, LayerType.Grills, true)) { //TODO damage amt based off type of bullet AddGrillDamage(bullet.damage, data, cellPos, bulletHitTarget, AttackType.Bullet); } } } if (bullet.isMiningBullet) { if (Layer.LayerType == LayerType.Walls) { LayerTile getTile = metaTileMap.GetTile(cellPos, LayerType.Walls); if (getTile != null) { if (Validations.IsMineableAt(bulletHitTarget, metaTileMap)) { SoundManager.PlayNetworkedAtPos("BreakStone", bulletHitTarget); var tile = getTile as BasicTile; Spawn.ServerPrefab(tile.SpawnOnDeconstruct, bulletHitTarget, count: tile.SpawnAmountOnDeconstruct); tileChangeManager.RemoveTile(cellPos, LayerType.Walls); } } } } }
private void Awake() { initialOffset = Vector3Int.CeilToInt(gameObject.transform.position); reactionManager = GetComponent <ReactionManager>(); metaDataLayer = GetComponent <MetaDataLayer>(); MatrixMove = GetComponentInParent <MatrixMove>(); tileChangeManager = GetComponentInParent <TileChangeManager>(); OnEarthquake.AddListener((worldPos, magnitude) => { var cellPos = metaTileMap.WorldToCell(worldPos); var bounds = new BoundsInt(cellPos - new Vector3Int(magnitude, magnitude, 0), new Vector3Int(magnitude * 2, magnitude * 2, 1)); foreach (var pos in bounds.allPositionsWithin) { foreach (var player in Get <PlayerScript>(pos, true)) { if (player.IsGhost) { continue; } player.registerTile.ServerSlip(true); } //maybe shake items somehow, too } }); }
public IEnumerator KineticAnim(Collision2D coll) { Transform cellTransform = rigidBody.gameObject.transform; MetaTileMap layerMetaTile = cellTransform.GetComponentInParent <MetaTileMap>(); ContactPoint2D firstContact = coll.GetContact(0); Vector3 hitPos = firstContact.point; Vector3 forceDir = Direction; forceDir.z = 0; Vector3 bulletHitTarget = hitPos + (forceDir * 0.2f); Vector3Int cellPos = layerMetaTile.WorldToCell(Vector3Int.RoundToInt(bulletHitTarget)); TileChangeManager tileChangeManager = transform.GetComponentInParent <TileChangeManager>(); // Store the old effect LayerTile oldEffectLayerTile = tileChangeManager.GetLayerTile(cellPos, LayerType.Effects); tileChangeManager.UpdateTile(cellPos, TileType.Effects, "KineticAnimation"); yield return(WaitFor.Seconds(.4f)); tileChangeManager.RemoveTile(cellPos, LayerType.Effects); // Restore the old effect if any (ex: cracked glass, does not work) if (oldEffectLayerTile) { tileChangeManager.UpdateTile(cellPos, oldEffectLayerTile); } isOnDespawn = false; global::Despawn.ClientSingle(gameObject); }
public IEnumerator KineticAnim() { Transform cellTransform = rigidBody.gameObject.transform; MetaTileMap layerMetaTile = cellTransform.GetComponentInParent <MetaTileMap>(); var position = layerMetaTile.WorldToCell(Vector3Int.RoundToInt(rigidBody.gameObject.AssumedWorldPosServer())); TileChangeManager tileChangeManager = transform.GetComponentInParent <TileChangeManager>(); // Store the old effect LayerTile oldEffectLayerTile = tileChangeManager.GetLayerTile(position, LayerType.Effects); tileChangeManager.UpdateTile(position, TileType.Effects, "KineticAnimation"); yield return(WaitFor.Seconds(.4f)); tileChangeManager.RemoveTile(position, LayerType.Effects); // Restore the old effect if any (ex: cracked glass, does not work) if (oldEffectLayerTile) { tileChangeManager.UpdateTile(position, oldEffectLayerTile); } isOnDespawn = false; global::Despawn.ClientSingle(gameObject); }
//Script does not work on asteroids but mines AsteroidStation ore public void BulletHitInteract(Collision2D coll, Vector2 Direction) { Transform cellTransform = coll.transform; MetaTileMap layerMetaTile = cellTransform.GetComponentInParent <MetaTileMap>(); TileChangeManager tileChangeManager = cellTransform.GetComponentInParent <TileChangeManager>(); ContactPoint2D firstContact = coll.GetContact(0); Vector3 hitPos = firstContact.point; Vector3 forceDir = Direction; forceDir.z = 0; Vector3 bulletHitTarget = hitPos + (forceDir * 0.2f); Vector3Int cellPos = layerMetaTile.WorldToCell(Vector3Int.RoundToInt(bulletHitTarget)); LayerTile getTile = layerMetaTile.GetTile(cellPos, LayerType.Walls); if (getTile != null) { if (Validations.IsMineableAt(bulletHitTarget, layerMetaTile)) { SoundManager.PlayNetworkedAtPos("BreakStone", bulletHitTarget); var tile = getTile as BasicTile; Spawn.ServerPrefab(tile.SpawnOnDeconstruct, bulletHitTarget, count: tile.SpawnAmountOnDeconstruct); tileChangeManager.RemoveTile(cellPos, LayerType.Walls); tileChangeManager.RemoveTile(cellPos, LayerType.Effects); } return; } }
public void OnHover() { if (!UIManager.IsMouseInteractionDisabled && UIManager.Hands.CurrentSlot != null) { // get mouse position Vector3 mousePosition = Camera.main.ScreenToWorldPoint(CommonInput.mousePosition); // round mouse position Vector3Int roundedMousePosition = Vector3Int.RoundToInt(mousePosition); // if distance is greater than interaction distance if (Vector2.Distance(transform.position, (Vector3)roundedMousePosition) > PlayerScript.interactionDistance) { DisableVisualisation(); return; } // if position has changed and player has cable in hand if (roundedMousePosition != lastMouseWordlPositionInt && Validations.HasItemTrait(UIManager.Hands.CurrentSlot.ItemObject, CommonTraits.Instance.Cable)) { lastMouseWordlPositionInt = roundedMousePosition; // get metaTileMap and top tile // MetaTileMap metaTileMap = MatrixManager.AtPoint(roundedMousePosition, false).MetaTileMap; // LayerTile topTile = metaTileMap.GetTile(metaTileMap.WorldToCell(mousePosition), true); // *code above works only on Station matrix // TODO: replace GetComponent solution with some built-in method? var hit = MouseUtils.GetOrderedObjectsUnderMouse().FirstOrDefault(); MetaTileMap metaTileMap = hit.GetComponentInChildren <MetaTileMap>(); if (metaTileMap) { LayerTile topTile = metaTileMap.GetTile(metaTileMap.WorldToCell(roundedMousePosition), true); if (topTile && (topTile.LayerType == LayerType.Base || topTile.LayerType == LayerType.Underfloor)) { // move cable placement visualisation to rounded mouse position and enable it cablePlacementVisualisation.transform.position = roundedMousePosition - new Vector3(0.5f, 0.5f, 0);; cablePlacementVisualisation.SetActive(true); } // disable visualisation if active else { DisableVisualisation(); } } else { DisableVisualisation(); } } } else { DisableVisualisation(); } }
/// <summary> /// Method for mining ore /// </summary> /// <param name="worldPosition"></param> /// <returns></returns> public bool TryMine(Vector3 worldPosition) { Vector3Int cellPos = metaTileMap.WorldToCell(worldPosition); var getTile = metaTileMap.GetTile(cellPos, LayerType.Walls) as BasicTile; if (getTile == null || getTile.Mineable == false) { return(false); } SoundManager.PlayNetworkedAtPos(SingletonSOSounds.Instance.BreakStone, worldPosition); Spawn.ServerPrefab(getTile.SpawnOnDeconstruct, worldPosition, count: getTile.SpawnAmountOnDeconstruct); tileChangeManager.RemoveTile(cellPos, LayerType.Walls); tileChangeManager.RemoveOverlay(cellPos, LayerType.Effects); return(true); }
private void Awake() { metaTileMap = GetComponent <MetaTileMap>(); if (metaTileMap == null) { Logger.LogError($"MetaTileMap was null on {gameObject.name}"); } networkedMatrix = transform.parent.GetComponent <NetworkedMatrix>(); initialOffset = Vector3Int.CeilToInt(gameObject.transform.position); reactionManager = GetComponent <ReactionManager>(); metaDataLayer = GetComponent <MetaDataLayer>(); MatrixMove = GetComponentInParent <MatrixMove>(); tileChangeManager = GetComponentInParent <TileChangeManager>(); underFloorLayer = GetComponentInChildren <UnderFloorLayer>(); tilemapsDamage = GetComponentsInChildren <TilemapDamage>().ToList(); if (MatrixManager.Instance.InitializingMatrixes.ContainsKey(gameObject.scene) == false) { MatrixManager.Instance.InitializingMatrixes.Add(gameObject.scene, new List <Matrix>()); } MatrixManager.Instance.InitializingMatrixes[gameObject.scene].Add(this); OnEarthquake.AddListener((worldPos, magnitude) => { var cellPos = metaTileMap.WorldToCell(worldPos); var bounds = new BoundsInt(cellPos - new Vector3Int(magnitude, magnitude, 0), new Vector3Int(magnitude * 2, magnitude * 2, 1)); foreach (var pos in bounds.allPositionsWithin) { foreach (var player in Get <PlayerScript>(pos, true)) { if (player.IsGhost) { continue; } player.registerTile.ServerSlip(true); } //maybe shake items somehow, too } }); }
public void OnHover() { if (!UIManager.IsMouseInteractionDisabled) { // get mouse position Vector3 mousePosition = Camera.main.ScreenToWorldPoint(CommonInput.mousePosition); // round mouse position Vector3Int roundedMousePosition = Vector3Int.RoundToInt(mousePosition); // if distance is greater than interaction distance if (Vector2.Distance(transform.position, (Vector3)roundedMousePosition) > PlayerScript.interactionDistance) { DisableVisualisation(); return; } // if position has changed and player has cable in hand if (roundedMousePosition != lastMouseWordlPositionInt && Validations.HasItemTrait(UIManager.Hands.CurrentSlot.ItemObject, CommonTraits.Instance.Cable)) { lastMouseWordlPositionInt = roundedMousePosition; // get metaTileMap and top tile MetaTileMap metaTileMap = MatrixManager.AtPoint(roundedMousePosition, false).MetaTileMap; LayerTile topTile = metaTileMap.GetTile(metaTileMap.WorldToCell(mousePosition), true); if (topTile && (topTile.LayerType == LayerType.Base || topTile.LayerType == LayerType.Underfloor)) { // move cable placement visualisation to rounded mouse position and enable it cablePlacementVisualisation.transform.position = roundedMousePosition - new Vector3(0.5f, 0.5f, 0);; cablePlacementVisualisation.SetActive(true); } // disable visualisation if active else { DisableVisualisation(); } } } else { DisableVisualisation(); } }
public float ApplyDamage(float dmgAmt, AttackType attackType, Vector3 worldPos) { Vector3Int cellPosition = metaTileMap.WorldToCell(worldPos); return(DealDamageAt(dmgAmt, attackType, cellPosition, worldPos)); }