public virtual void Update(Timestep timestep, EntityUniverseFacade entityUniverseFacade, bool inherited = false) { if (TilePower == null) { return; } if (entityUniverseFacade.ReadTile(Location, TileAccessFlags.SynchronousWait, out var tile)) { if (tile.Configuration.Components.Select <ChargeableComponent>().Any()) { TilePower.GetPowerFromComponent(tile.Configuration.Components.Select <ChargeableComponent>().First()); } else { entityUniverseFacade.RemoveEntity(Entity.Id); return; } } Universe = entityUniverseFacade; if (!inherited) { Cycle.RunCycle(RunCycle); } }
public override void Control(Entity entity, EntityUniverseFacade facade, ControlState main, ControlState alt) { if (!main.DownClick) { return; } if (entity.PlayerEntityLogic.LookingAtTile(out var target, out _)) { if (facade.TryGetLightPower(target, out var efficiency, out var phase, out var reductions)) { var notificationParams = new NotificationParams(3); notificationParams.SetString(0, efficiency + "%"); notificationParams.SetFloat(1, phase); notificationParams.SetFloat(2, reductions); var notification = GameContext.NotificationDatabase.CreateNotificationFromCode( "nimbusfox.powerapi.notifications.lightInformation", facade.Step, notificationParams, true); entity.PlayerEntityLogic.ShowNotification(notification); } } }
public override void SpawnBot(Entity entity, EntityUniverseFacade facade, Vector3I location) { if (entity.Logic is PlayerEntityLogic logic) { BotEntityBuilder.Spawn(location, facade, logic.DisplayName(), logic.Uid()); } }
public override bool TryResolveAltInteractVerb(Entity entity, EntityUniverseFacade facade, Vector3I location, TileConfiguration lookedAtTile, out string verb) { verb = "nimbusfox.powerapi.verb.changeMode"; return(false); }
public override void Control(Entity entity, EntityUniverseFacade facade, ControlState main, ControlState alt) { if (main.DownClick || alt.DownClick) { if (entity.Logic is PlayerEntityLogic logic) { if (logic.LookingAtTile(out var target, out var location)) { if (_selectionEntity == null) { CreateSelectionEntity(entity, facade, location); } else if (_selectionEntity.Removed) { CreateSelectionEntity(entity, facade, location); } if (_selectionEntity?.Logic is BorderEntityLogic borderLogic) { if (main.DownClick) { borderLogic.SetPos1(target); } if (alt.DownClick) { borderLogic.SetPos2(target); } borderLogic.SetBorderTiles(WandComponent); } } } } }
public override void Construct(Blob arguments, EntityUniverseFacade entityUniverseFacade) { Location = arguments.FetchBlob("location").GetVector3I(); Universe = entityUniverseFacade; if (TilePower == null) { TilePower = new Power(ModelUpdate); if (entityUniverseFacade.ReadTile(Location, TileAccessFlags.SynchronousWait, out var tile)) { if (tile.Configuration.Components.Contains <ChargeableComponent>()) { TilePower.GetPowerFromComponent(tile.Configuration.Components.Get <ChargeableComponent>()); } Tile = tile.Configuration.Code; } } if (arguments.Contains("charge")) { TilePower.SetPower(arguments.GetLong("charge")); } Entity.Physics.ForcedPosition(Location.ToTileCenterVector3D()); }
public static ITileWithPower GetPowerForTile(this object target, EntityUniverseFacade facade) { if (target is ITileWithPower power) { return(power); } if (target is ChargeableTileStateEntityLogic logic) { var id = logic.GetOwner(); if (id == EntityId.NullEntityId) { return(null); } if (facade.TryGetEntity(id, out var entity)) { if (entity.Logic is ITileWithPower tilePower) { return(tilePower); } } } return(null); }
public override void PostUpdate(Timestep timestep, EntityUniverseFacade entityUniverseFacade) { if (_done) { entityUniverseFacade.RemoveEntity(_entity.Id); CanDispose = true; Dispose(); } }
public override void RestoreFromPersistedData(Blob data, EntityUniverseFacade facade) { Entity.Construct(data.GetBlob("constructData"), facade); base.RestoreFromPersistedData(data, facade); _done = data.GetBool("done"); NeedsStore(); }
public override void Interact(Entity entity, EntityUniverseFacade facade, ControlState main, ControlState alt) { if (!alt.DownClick) { return; } if (!IsClaimed()) { var player = entity.PlayerEntityLogic; player.ShowNotification(GameContext.NotificationDatabase.CreateNotificationFromCode(Component.NotClaimedNotification, entity.Step, NotificationParams.EmptyParams)); return; } if (!Totem.IsReady()) { var player = entity.PlayerEntityLogic; player.ShowNotification(GameContext.NotificationDatabase.CreateNotificationFromCode(Component.NotReadyNotification, entity.Step, NotificationParams.EmptyParams)); return; } if (Totem.CanStartNewGame()) { Totem.ResetGame(); PrepareReset(facade.Step); } }
public override void Update(Timestep timestep, EntityUniverseFacade entityUniverseFacade) { if (TilePower == null) { return; } Universe = entityUniverseFacade; if (entityUniverseFacade.ReadTile(Location, TileAccessFlags.SynchronousWait, out var tile)) { var config = GameContext.TileDatabase.GetTileConfiguration(Tile); if (config.Components.Select <ChargeableComponent>().Any() && tile.Configuration.Code != "staxel.tile.Sky") { TilePower.GetPowerFromComponent(config.Components.Select <ChargeableComponent>().First()); } else { var itemBlob = BlobAllocator.Blob(true); itemBlob.SetString("kind", "staxel.item.Placer"); itemBlob.SetString("tile", Tile); var item = GameContext.ItemDatabase.SpawnItemStack(itemBlob, null); ItemEntityBuilder.SpawnDroppedItem(Entity, entityUniverseFacade, item, Entity.Physics.Position, new Vector3D(0, 1, 0), Vector3D.Zero, SpawnDroppedFlags.None); entityUniverseFacade.RemoveEntity(Entity.Id); return; } Cycle.RunCycle(RunCycle); } }
public override void PostUpdate(Timestep timestep, EntityUniverseFacade universe) { if (_done) { universe.RemoveEntity(Entity.Id); } }
public void SpawnFireworks(EntityUniverseFacade universe) { Item item; if (SpawnRed) { item = GameContext.ItemDatabase.SpawnItem(_goalComponent.RedGoalFireworkItem, null); } else { item = GameContext.ItemDatabase.SpawnItem(_goalComponent.BlueGoalFireworkItem, null); } for (var i = 0; i < _goalComponent.FireworkItemQuantity; ++i) { if (item.Configuration.Components.Contains <FireworkComponent>()) { FireworkEntityBuilder.SpawnFirework(Entity, universe, item, _countPosition, _goalComponent.FireworkLaunchVelocity + _goalComponent.FireworkLaunchVelocitySpread * GameContext.RandomSource.NextVector3DInSphere(), _goalComponent.FireworkFlightSeconds + _goalComponent.FireworkFlightSecondsSpread * GameContext.RandomSource.NextFloat(0f, 1f)); } else { ItemEntityBuilder.SpawnDroppedItem(Entity, universe, new ItemStack(item, 1), _countPosition, _goalComponent.FireworkLaunchVelocity + _goalComponent.FireworkLaunchVelocitySpread * GameContext.RandomSource.NextVector3DInSphere(), Vector3D.Zero, SpawnDroppedFlags.AchievementValid | SpawnDroppedFlags.SpawnJitter); } } }
protected void CreateSelectionEntity(Entity entity, EntityUniverseFacade facade, Vector3I location) { if (entity.Logic is PlayerEntityLogic logic) { _selectionEntity = BorderEntityBuilder.Spawn(location, facade, entity); } }
public override void Update(Timestep timestep, EntityUniverseFacade entityUniverseFacade) { var locations = new List <Vector3I> { new Vector3I(Location.X + 1, Location.Y, Location.Z), new Vector3I(Location.X - 1, Location.Y, Location.Z), new Vector3I(Location.X, Location.Y, Location.Z + 1), new Vector3I(Location.X, Location.Y, Location.Z - 1) }; var efficiency = 0; foreach (var location in locations) { if (entityUniverseFacade.ReadTile(location, TileAccessFlags.SynchronousWait, out var tile)) { var component = tile.Configuration.Components.Select <WaterWheelTileComponent>().FirstOrDefault(); if (component != default(WaterWheelTileComponent)) { efficiency = component.Efficency; break; } } } base.Update(timestep, entityUniverseFacade, efficiency); }
public override void PostUpdate(Timestep timestep, EntityUniverseFacade universe) { //If this has been set. Remove this entity. if (this._isRemoved) { universe.RemoveEntity(Entity.Id); } }
public override void Interact(Entity entity, EntityUniverseFacade facade, ControlState main, ControlState alt) { if (!alt.DownClick) { return; } entity.PlayerEntityLogic.NextAction(Configuration.InteractActionTrigger); }
public override void PostUpdate(Timestep timestep, EntityUniverseFacade entityUniverseFacade) { if (_remove) { Entity.SetRemoved(); entityUniverseFacade.RemoveEntity(Entity.Id); } }
public override void PostUpdate(Timestep timestep, EntityUniverseFacade entityUniverseFacade) { if (!entityUniverseFacade.TryGetEntity(Owner, out _)) { Entity.SetRemoved(); entityUniverseFacade.RemoveEntity(Entity.Id); } }
public override bool TryResolveMainInteractVerb(Entity entity, EntityUniverseFacade facade, Vector3I location, TileConfiguration lookedAtTile, out string verb) { verb = facade.AnyInnerCableEntitiesInTile(location, out _) ? "nimbusfox.powerapi.verb.extract" : "nimbusfox.powerapi.verb.insert"; return(true); }
public override void PreUpdate(Timestep timestep, EntityUniverseFacade entityUniverseFacade) { if (!_lookedAtLinger) { _lookedAt = false; } _lookedAtLinger = false; }
public override void Start(Entity entity, EntityUniverseFacade facade) { if (entity.Logic is BinTileStateEntityLogic logic) { logic.ProcessBin(facade); } entity.Logic.ActionFacade.NoNextAction(); }
public override void RenderUpdate(Timestep timestep, Entity entity, AvatarController avatarController, EntityUniverseFacade facade, int updateSteps) { if (entity.Logic is BotEntityLogic logic) { if (_botTileCode != logic.BotTile) { _botTileCode = logic.BotTile; _bot = Helpers.MakeTile(_botTileCode).Configuration.Icon.Matrix(); } if (_bladeTileCode != logic.BotComponent.BladeModel) { _bladeTileCode = logic.BotComponent.BladeModel; _bladeTile = Helpers.MakeTile(_bladeTileCode); } if (NameTag == null) { NameTag = ClientContext.NameTagRenderer.RegisterNameTag(entity.Id); } if (logic.UpdateColors) { WorldEditHook.Instance.CreateCache(); var botTile = Helpers.MakeTile(_botTileCode); var matrix = botTile.Configuration.Icon as MatrixDrawable; var bot = botTile.Configuration.Icon.GetPrivateFieldValue <CompactVertexDrawable>("_drawable"); var list = bot.CompileToVoxelVertexArray(); if (WorldEditHook.Cache.ContainsKey(_botTileCode)) { foreach (var cache in WorldEditHook.Cache[_botTileCode]) { foreach (var color in logic.ColorReplace) { if (color.Key.R + cache.Value.r == list[cache.Key].Color.R && color.Key.G + cache.Value.g == list[cache.Key].Color.G && color.Key.B + cache.Value.b == list[cache.Key].Color.B) { list[cache.Key].Color = new Color(color.Value.R + cache.Value.r, color.Value.G + cache.Value.g, color.Value.B + cache.Value.b, list[cache.Key].Color.A); } } } } _bot = new VertexDrawable(list.ToList()).Matrix(matrix.MatrixValue); logic.UpdateColors = false; } } }
public override void RestoreFromPersistedData(Blob data, EntityUniverseFacade facade) { if (data.Contains("construct")) { Construct(data.FetchBlob("construct"), facade); } if (data.Contains("position")) { Entity.Physics.ForcedPosition(data.FetchBlob("position").GetVector3D()); } if (data.Contains("destination")) { _destination = data.FetchBlob("destination").GetVector3D(); } if (data.Contains("rotation")) { Rotation = (int)data.GetLong("rotation"); } if (data.Contains("botTile")) { BotTile = data.GetString("botTile"); BotComponent = GameContext.TileDatabase.GetTileConfiguration(BotTile).Components.Get <BotComponent>(); } if (data.Contains("owner")) { Owner = data.GetString("owner"); } if (data.Contains("uid")) { OwnerUid = data.GetString("uid"); } if (data.Contains("colorReplace")) { var colorReplace = new Dictionary <Color, Color>(); foreach (var entry in data.FetchBlob("colorReplace").KeyValueIteratable) { if (uint.TryParse(entry.Key, out var colKey)) { if (uint.TryParse(entry.Value.GetString(), out var colVal)) { colorReplace.Add(ColorMath.FromRgba(colKey), ColorMath.FromRgba(colVal)); } } } ColorReplace = colorReplace; } }
public override void RestoreFromPersistedData(Blob data, EntityUniverseFacade facade) { Entity.Construct(data.GetBlob("constructData"), facade); base.RestoreFromPersistedData(data, facade); _done = data.GetBool("done"); _countPosition = data.GetBlob("countPosition").GetVector3D(); GoalCount = (int)data.GetLong("goalCount", 0); Store(); }
public override void Construct(Blob arguments, EntityUniverseFacade entityUniverseFacade) { base.Construct(arguments, entityUniverseFacade); if (arguments.Contains("tile")) { Tile = arguments.GetString("tile"); } }
public override void RestoreFromPersistedData(Blob data, EntityUniverseFacade facade) { Entity.Construct(data.GetBlob("constructData"), facade); base.RestoreFromPersistedData(data, facade); _done = data.GetBool("done"); _ballSpawned = _blob.GetBool("ballSpawned", true); RoundStartedTimestep = _blob.GetTimestep("roundStartedTimestep", Timestep.Null); Store(); }
public override void RestoreFromPersistedData(Blob data, EntityUniverseFacade facade) { base.RestoreFromPersistedData(data, facade); if (data.Contains("tile")) { Tile = data.GetString("tile"); } }
public override void Control(Entity entity, EntityUniverseFacade facade, ControlState main, ControlState alt) { if (!main.DownClick) { return; } entity.Logic.ActionFacade.NextAction(LauncherEntityAction.KindCode()); }
public override void Construct(Blob arguments, EntityUniverseFacade entityUniverseFacade) { _constructBlob = BlobAllocator.Blob(true); _constructBlob.MergeFrom(arguments); Entity.Physics.ForcedPosition(arguments.FetchBlob("location").GetVector3I().ToVector3D()); Owner = arguments.GetLong("owner"); NeedsStore(); }