private void ApplyCharacterSettings() { if (!_settingsApplied) { _settingsApplied = true; UIStateMachine.Instance.TransitionTo(UIStateType.Gameplay); CursorOverlayService.Instance.ResetCursorToDefault(); // Publish player asset (will sync across network) _doodleAsset.SetTexture(_doodelDraw.ExportCurrentDoodleTexture()); PlayerAssetManager.Instance.PublishAssetChanges(_doodleAsset.Guid); // Set doodle SimPlayerInputSetPawnDoodle setPawnDoodleInput = new SimPlayerInputSetPawnDoodle(_doodleAsset.Guid, _characterIsLookingRightToggle.isOn); SimWorld.SubmitInput(setPawnDoodleInput); if (!s_consoleSkipCharacterCreation) { // record pawn name for future use PromptDisplay.Instance.AskString("Enter your character name here :", (string characterName) => { // Set name SimPlayerInputSetPawnName startNameInput = new SimPlayerInputSetPawnName(characterName); SimWorld.SubmitInput(startNameInput); _settingsApplied = false; }); } } }
private void UpdateRangeFeedback() { if (SimWorld.TryGetComponent(CurrentContext.Instigator, out FixTranslation position)) { _instigatorPosition = (Vector2)position.Value; } var paramEntity = CurrentContext.GetQueryParam <GameActionParameterEntity.Description>(); float range = paramEntity == null ? float.MaxValue : (float)paramEntity.RangeFromInstigator; bool inRange = (Cache.PointerWorldPosition - _instigatorPosition).magnitude < range; if (inRange) { CursorOverlayService.Instance.SetCursorColor(_normalColor); } else { CursorOverlayService.Instance.SetCursorColor(_outOfRangeColor); } if (range < 1000) { _rangeIndicator1.gameObject.SetActive(true); _rangeIndicator2.gameObject.SetActive(true); _rangeIndicator1.localScale = Vector3.one * range * 2f; _rangeIndicator2.localScale = _rangeIndicator1.localScale + Vector3.one * _rangeIndicatorScaleDiff * Cache.CameraSize; } else { _rangeIndicator1.gameObject.SetActive(false); _rangeIndicator2.gameObject.SetActive(false); } }
public override void OnPostSimulationTick() { base.OnPostSimulationTick(); _isOn = SimWorld.TryGetComponent(SimEntity, out Signal signal) && signal; _wasOn |= _isOn; }
private bool isItemSelectable(int index) { if (!this.m_enabled) { return(false); } AppEngine canvas = AppEngine.getCanvas(); SimData simData = canvas.getSimData(); SimWorld simWorld = canvas.getSimWorld(); switch (this.m_listId) { case 0: case 2: case 7: case 10: case 11: case 12: case 13: return(true); case 5: int inventoryNthItem = simData.getInventoryNthItem(index); return((simWorld.getItemFlags(inventoryNthItem) & 4) != 0); case 6: return(true); default: return(false); } }
private void HideCostPreview() { if (SimWorld.HasComponent <ActionPoints>(_itemsOwner)) { HUDDisplay.Instance.APEnergyBarDisplay.StopShowingPreview(); } }
void IWorldUIPointerClickHandler.OnPointerClick() { if (!Cache.LocalPawnAlive) { return; } fix2 entityPosition = SimWorld.GetComponent <FixTranslation>(SimEntity); fix2 pawnPosition = Cache.LocalPawnPosition; if (fixMath.distancemanhattan(entityPosition, pawnPosition) > SimulationGameConstants.InteractibleMaxDistanceManhattan) { PresentationHelpers.RequestFloatingText((Vector2)entityPosition, "Trop loin", Color.white); return; } switch (_clickAction) { case ClickAction.OpenChest: if (InteractableInventoryDisplaySystem.Instance != null) { InteractableInventoryDisplaySystem.Instance.SetupDisplayForInventory(SimEntity); } break; case ClickAction.TriggerSignal: PresentationHelpers.RequestFloatingText((Vector2)entityPosition, "Click", Color.white); SimWorld.SubmitInput(new SimPlayerInputClickSignalEmitter(SimEntity)); break; } }
protected override void OnGamePresentationUpdate() { PhysicsVelocity velocity = SimWorld.GetComponent <PhysicsVelocity>(SimEntity); bool spriteLookingRight = _spriteLookingRight; if (SimWorld.HasComponent <DoodleStartDirection>(SimEntity)) { spriteLookingRight = SimWorld.GetComponent <DoodleStartDirection>(SimEntity).IsLookingRight; } int lookDir = 0; if (velocity.Linear.x > (fix)0.05f) { lookDir = 1; } else if (velocity.Linear.x < -(fix)0.05f) { lookDir = -1; } if (lookDir != 0) { Quaternion rot = _bone.localRotation; Vector3 eulerAngles = rot.eulerAngles; eulerAngles.y = (lookDir == 1 ^ spriteLookingRight) ? 180f : 0f; rot.eulerAngles = eulerAngles; _bone.localRotation = rot; } }
protected override void OnGamePresentationUpdate() { if (SimWorld.TryGetComponent(SimEntity, out Signal signal)) { ContainerToDisplay.SetActive(signal.Value); } }
private void UpdateState() { if (Cache.LocalPawn == Entity.Null) { // If we don't have a pawn _viewState.Set(TurnState.NotMyTurn); } else if (!Cache.DEPRECATED_CanLocalPlayerPlay && SimWorld.HasSingleton <GameStartedTag>()) { // if it's not our turn to play _viewState.Set(TurnState.NotMyTurn); } else { // if it's our turn to play if (SimWorld.TryGetComponent(Cache.LocalController, out ReadyToPlay ready) && ready.Value) { _viewState.Set(TurnState.Ready); } else { _viewState.Set(TurnState.NotReady); } } }
private void HideCostPreview() { if (SimWorld.HasComponent <ActionPoints>(CurrentContext.Instigator)) { HUDDisplay.Instance.APEnergyBarDisplay.StopShowingPreview(); } }
private void OnIntentionToUsePrimaryActionOnItem(int ItemIndex) { if (!_interactible) { return; } if (SimWorld.TryGetBufferReadOnly(Cache.LocalPawn, out DynamicBuffer <InventoryItemReference> inventory)) { if (inventory.Length > ItemIndex && ItemIndex > -1) { InventoryItemReference item = inventory[ItemIndex]; if (SimWorld.Exists(item.ItemEntity)) { Entity itemEntity = item.ItemEntity; if (SimWorld.TryGetComponent(itemEntity, out ItemAction itemAction)) { UIStateMachine.Instance.TransitionTo(UIStateType.ParameterSelection, new ParameterSelectionState.InputParam() { ActionInstigator = itemEntity, ActionPrefab = itemAction.Value, IsItem = true, ItemIndex = ItemIndex }); } } } } }
[SerializeField] private AudioPlayable _damageSound; // global for now but can be per character/ennemy protected override void OnGamePresentationUpdate() { if (_audioSource == null) { return; } // Item sounds foreach (var gameActionEvent in PresentationEvents.GameActionEvents.SinceLastPresUpdate) { SimWorld.TryGetComponent(gameActionEvent.GameActionContext.Action, out SimAssetId entitySimAssetID); GameObject entityPrefab = PresentationHelpers.FindSimAssetPrefab(entitySimAssetID); if (entityPrefab != null) { var sfx = entityPrefab.GetComponent <GameActionAuth>()?.SfxOnUse; if (sfx != null) { sfx.PlayOn(_audioSource); } } } // Damage sounds foreach (var hpDeltaEvent in PresentationEvents.HealthDeltaEvents.SinceLastPresUpdate) { if (_damageSound != null) { _damageSound.PlayOn(_audioSource); } } }
private bool HandleDeathAnimation() { if (SimWorld.HasComponent <DeadTag>(SimEntity)) { if (_previousState != AnimationType.Death) { TriggerAnimationInteruptionOnStateChange(); _hasTriggeredAnAnimation = true; _lastTransitionTime = SimWorld.Time.ElapsedTime; AnimationDefinition anim = FindAnimation(AnimationType.Death); if (anim != null) { anim.TriggerAnimation(SimEntity, _spriteStartPos, _bone, null); } _previousState = AnimationType.Death; } return(true); } return(false); }
protected override void OnGamePresentationUpdate() { if (TryGetComponent(out BindedSimEntityManaged bindedSimEntity)) { Entity pawnController = CommonReads.TryGetPawnController(SimWorld, bindedSimEntity.SimEntity); if (SimWorld.TryGetComponent(pawnController, out Team pawnTeam)) { Color spriteColor = new Color(); switch ((DesignerFriendlyTeam)pawnTeam.Value) { case DesignerFriendlyTeam.Player: spriteColor = Color.white; break; case DesignerFriendlyTeam.Baddies: if (IsElite) { spriteColor = Color.magenta; } else { spriteColor = Color.red; } break; } SpriteRenderer.color = spriteColor; return; } } }
public void setSubType(int subType, int focusItem) { AppEngine canvas = AppEngine.getCanvas(); SimData simData = canvas.getSimData(); SimWorld simWorld = canvas.getSimWorld(); int subType1 = this.m_subType; this.m_subType = subType; this.m_focusItem = focusItem; switch (subType) { case -1: if (subType1 != -1) { this.resetSwiping(true); } this.m_focusItem = -1; break; case 10: this.m_titleId = simData.getSimName(focusItem); this.resetSwiping(false); break; case 11: this.m_titleId = simWorld.getItemDescString(focusItem); this.resetSwiping(false); break; } }
protected override IEnumerator SurveyRoutine(Context context, List <GameAction.ParameterData> result, System.Action complete, System.Action cancel) { //Setup _trajectoryDisplay = TrajectoryDisplaySystem.Instance.CreateTrajectory(); _weaponPreview.SetActive(false); _shootAimingState = ShootAimingState.SelectingDirection; _vectorDesc = context.GetQueryParam <GameActionParameterVector.Description>(); if (_vectorDesc.UsePreviousParameterOriginLocation && context.CurrentData.Count > 0) { // could fetch all previous to find a valid one if (context.CurrentData[context.CurrentData.Count - 1] is GameActionParameterPosition.Data posData) { transform.position = posData.Position.ToUnityVec(); } else if (context.CurrentData[context.CurrentData.Count - 1] is GameActionParameterEntity.Data entityData) { _originEntity = entityData.Entity; if (SimWorld.TryGetComponent(_originEntity, out FixTranslation fixTranslation)) { transform.position = fixTranslation.Value.ToUnityVec(); } } } while (_shootAimingState != ShootAimingState.Aiming) { UpdateDirection(); if (Input.GetKeyDown(KeyCode.Mouse0)) { _shootAimingState = ShootAimingState.Aiming; } yield return(null); } _weaponPreview.SetActive(true); SetupAimingRotationAnimation(); while (_shootAimingState != ShootAimingState.Shoot) { if (Input.GetKeyDown(KeyCode.Mouse0)) { _rotatingAnimation.Kill(); _shootAimingState = ShootAimingState.Shoot; } yield return(null); } Vector2 _finalVector = ViewToSimVector((_line.position - transform.position) * 2); result.Add(new GameActionParameterVector.Data((fix2)_finalVector)); complete(); }
protected override void OnGamePresentationUpdate() { if (SimEntity != Entity.Null && SimWorld.TryGetComponent(SimEntity, out Name name)) { _displayName.Set(name); } else { _displayName.Set(default);
private void ShowCostPreview() { if (SimWorld.TryGetComponent(CurrentContext.Instigator, out ActionPoints ap)) { if (SimWorld.TryGetComponent(CurrentContext.ActionPrefab, out ItemSettingAPCost apCost)) { HUDDisplay.Instance.APEnergyBarDisplay.ShowPrevewAPEnergyCost((float)ap.Value - apCost.Value); } } }
public void setTypeAndFacing(int type, int facing) { HouseObject.requireVaildType(type); HouseObject.requireValidFacing(facing); SimWorld simWorld = AppEngine.getCanvas().getSimWorld(); this.setSize(simWorld.getObjectFootprintWidth(type), simWorld.getObjectFootprintHeight(type)); this.m_type = type; this.m_facing = facing; }
public void readBuiltIn(DataInputStream dis, int index) { this.m_packId = (short)-1; this.m_index = (short)index; this.m_descStringId = (int)SimWorld.lookupSimsWorld(dis); this.m_icon = SimWorld.lookupSimsWorld(dis); this.m_flags = dis.readInt(); this.m_buyPrice = dis.readShort(); this.m_sellPrice = dis.readShort(); this.m_maxInventory = dis.readByte(); }
private void HandleJump() { if (Input.GetKeyDown(KeyCode.Space)) { SimWorld.SubmitInput(new SimPlayerInputJump()); // This will mute all 'up' input until the player releases the 'up' key. // This is used to prevent the player for accidentally grabbing onto ladders when pressing both W and jump together _muteVerticalInputUntilRelease = true; } }
public void setFloorType(int newType) { if (newType == this.m_floorType) { return; } SimWorld simWorld = AppEngine.getCanvas().getSimWorld(); GeomStrip.remapTexCoords(this.m_compositeMesh, simWorld.getFloorTexCoords(this.m_floorType), simWorld.getFloorTexCoords(newType), 24); this.m_floorType = newType; }
protected override void OnGamePresentationUpdate() { if (SimWorld.HasComponent <Frozen>(SimEntity)) { SpriteRenderer.color = frozenColor; } else { SpriteRenderer.color = Color.white; } }
public override void Invoke(SimWorld world) { var request = new ActionRequest() { TargetEntity = world.GetEntityById(RequestEntityId), TargetLocation = RequestLocation, }; foreach (var entityId in EntityIds) { var entity = world.GetEntityById(entityId); entity.BeginAction(request); } base.Invoke(world); }
private void ShowCostPreview() { if (_currentItemGameActionAuth == null) { return; } if (SimWorld.TryGetComponent(_itemsOwner, out ActionPoints ap)) { HUDDisplay.Instance.APEnergyBarDisplay.ShowPrevewAPEnergyCost((float)ap.Value - _currentItemGameActionAuth.ApCost); } }
private void FinishAndSendSimInput() { // process completed, we have all info let's use the game action if (InputParameter.IsItem) { _surveySMBlackboard.ResultParameters.RemoveNulls(); SimPlayerInputUseItem simInput = new SimPlayerInputUseItem(InputParameter.ItemIndex, _surveySMBlackboard.ResultParameters); SimWorld.SubmitInput(simInput); } StateMachine.TransitionTo(UIStateType.Gameplay); }
protected override void OnGamePresentationUpdate() { if (SimWorld.TryGetComponent(SimEntity, out RemainingLifetime remainingLifetime) && SimWorld.TryGetComponent(SimEntity, out FixTranslation fixTranslation)) { int displayedRemaining = fixMath.ceilToInt(remainingLifetime); if (displayedRemaining != _previousDisplayedRemaining && displayedRemaining <= _maximumLifetimeForDisplay) { _previousDisplayedRemaining = displayedRemaining; FloatingTextSystem.Instance.RequestText(fixTranslation.Value.ToUnityVec(), displayedRemaining.ToString(), Color.white); } } }
protected override void OnGamePresentationUpdate() { if (SimWorld.TryGetComponent(SimEntity, out PhysicsVelocity velocity)) { float2 velocity2D = (float2)velocity.Linear; if (!velocity2D.Equals(float2(0, 0))) { float angle = degrees(angle2d(velocity2D)) + _offset; _tr.rotation = Quaternion.Euler(Vector3.forward * angle); } } }
protected override void OnGamePresentationUpdate() { foreach (var gameActionEvent in PresentationEvents.GameActionEvents.SinceLastPresUpdate) { SimWorld.TryGetComponent(gameActionEvent.GameActionContext.LastPhysicalInstigator, out FixTranslation lastPhysicalInstigatorTranslation); // ITEM USED VFX // only do the vfx if not an auto attack if (!SimWorld.HasComponent <AutoAttackAction>(gameActionEvent.GameActionContext.ActionInstigatorActor) || (SimWorld.TryGetComponent(gameActionEvent.GameActionContext.ActionInstigatorActor, out AutoAttackAction autoAttack) && autoAttack.Value != gameActionEvent.GameActionContext.Action)) { SimWorld.TryGetComponent(gameActionEvent.GameActionContext.ActionInstigatorActor, out SimAssetId instigatorAssetId); GameObject itemPrefab = PresentationHelpers.FindSimAssetPrefab(instigatorAssetId); if (itemPrefab != null && itemPrefab.TryGetComponent(out ItemAuth itemAuth)) { if (itemAuth.Icon != null && ItemUsedVFX != null) { ItemUsedVFX.TriggerVFX(new KeyValuePair <string, object>("Location", lastPhysicalInstigatorTranslation.Value.ToUnityVec()) , new KeyValuePair <string, object>("Sprite", itemAuth.Icon)); } } } // GAME ACTION USED VFX SimWorld.TryGetComponent(gameActionEvent.GameActionContext.Action, out SimAssetId gameActionAssetId); GameObject gameActionPrefab = PresentationHelpers.FindSimAssetPrefab(gameActionAssetId); if (gameActionPrefab != null && gameActionPrefab.TryGetComponent(out GameActionAuth gameActionAuth)) { VFXDefinition instigatorVFX = gameActionAuth.InstigatorVFX; if (instigatorVFX != null) { instigatorVFX.TriggerVFX(new KeyValuePair <string, object>("Location", lastPhysicalInstigatorTranslation.Value.ToUnityVec())); } VFXDefinition targetsVFX = gameActionAuth.TargetsVFX; if (targetsVFX != null && gameActionEvent.GameActionContext.Targets.IsCreated) { for (int i = 0; i < gameActionEvent.GameActionContext.Targets.Length; i++) { Entity target = gameActionEvent.GameActionContext.Targets[i]; if (SimWorld.TryGetComponent(target, out FixTranslation targetLocation)) { targetsVFX.TriggerVFX(new KeyValuePair <string, object>("Location", targetLocation.Value.ToUnityVec())); } } } } } }
public void init(int x, int z, int w, int h, int floorType, int wallType) { this.m_posX = x; this.m_posZ = z; this.m_sizeX = w; this.m_sizeZ = h; this.m_floorType = floorType; this.m_wallType = wallType; SimWorld simWorld = AppEngine.getCanvas().getSimWorld(); this.m_corners[0] = simWorld.createCorner(x, z); this.m_corners[1] = simWorld.createCorner(x + w, z); this.m_corners[2] = simWorld.createCorner(x + w, z + h); this.m_corners[3] = simWorld.createCorner(x, z + h); }
public override void OnUpdate() { if (Input.GetMouseButtonDown(1)) // right-click cancels { StateMachine.TransitionTo(UIStateType.Gameplay); return; } if (_surveySMBlackboard.IsDebug) { _surveyStateMachine.Update(); return; } if (!SimWorld.Exists(InputParameter.ActionInstigator)) // target item no longer exists, exit { StateMachine.TransitionTo(UIStateType.Gameplay); return; } // No currently running survey ? (or current survey done) if (_surveyStateMachine.CurrentState == null || ((SurveyState)_surveyStateMachine.CurrentState).Done) { bool isFinished = _surveySMBlackboard.ResultParameters.Count == _surveySMBlackboard.ParametersDescriptions.Length; if (isFinished) { // all done! send input and exit FinishAndSendSimInput(); } else { // not done, begin next survey state ? if (_surveySMBlackboard.ResultParameters.Count == 0) { // no data found, cancel and go back to gameplay StateMachine.TransitionTo(UIStateType.Gameplay); return; } else { // begin next survey state _surveyStateMachine.TransitionTo(new SurveyState()); } } } _surveyStateMachine.Update(); }
public virtual void Invoke(SimWorld world) { }