/// <summary> /// Try to split this stack into two. /// See <see cref="StackSplitEvent"/> /// </summary> private void OnStackSplit(EntityUid uid, StackComponent stack, StackSplitEvent args) { // If the stack doesn't have enough things as specified in the parameters, we do nothing. if (stack.Count < args.Amount) { return; } // Get a prototype ID to spawn the new entity. Null is also valid, although it should rarely be picked... var prototype = _prototypeManager.TryIndex <StackPrototype>(stack.StackTypeId, out var stackType) ? stackType.Spawn : stack.Owner.Prototype?.ID ?? null; // Remove the amount of things we want to split from the original stack... RaiseLocalEvent(uid, new StackChangeCountEvent(stack.Count - args.Amount), false); // Set the output parameter in the event instance to the newly split stack. args.Result = EntityManager.SpawnEntity(prototype, args.SpawnPosition); if (args.Result.TryGetComponent(out StackComponent? stackComp)) { // Set the split stack's count. RaiseLocalEvent(args.Result.Uid, new StackChangeCountEvent(args.Amount), false); } }
public async Task PerformAction(IEntity entity, IEntity?user) { if (entity.Deleted || string.IsNullOrEmpty(Prototype)) { return; } var entityManager = IoCManager.Resolve <IEntityManager>(); var coordinates = entity.Transform.Coordinates; if (EntityPrototypeHelpers.HasComponent <StackComponent>(Prototype)) { var _entity = entityManager.SpawnEntity(Prototype, coordinates); StackComponent stackComponent = _entity.GetComponent <StackComponent>(); stackComponent.Count = Math.Min(stackComponent.MaxCount, Amount); } else { for (var i = 0; i < Amount; i++) { entityManager.SpawnEntity(Prototype, coordinates); } } }
public void Init(bool isMyCharacter, int idx) { m_isMyCharacter = isMyCharacter; m_Model = transform.Find("people_face_01").gameObject; m_Model.transform.localPosition = Vector3.zero; m_Model.transform.localRotation = Quaternion.identity; m_Animator = GetComponentInChildren <Animator>(); m_Animator.enabled = false; m_animatorController = m_Animator.runtimeAnimatorController; m_CostumeComponent = Common.GetOrAddComponent <CostumeComponent>(gameObject); m_CostumeComponent.Init(); m_StackComponent = Common.GetOrAddComponent <StackComponent>(gameObject); m_StackComponent.Init(this); m_FSMCompnent = Common.GetOrAddComponent <FSMComponent>(gameObject); m_FSMCompnent.Init(this); m_InputComponent = Common.GetOrAddComponent <InputComponent>(gameObject); m_InputComponent.Init(this); OnVictory = m_StackComponent.OnVictory; if (m_BillBoard == null) { m_BillBoard = gameObject.GetComponentInChildren <BillBoard>(); } m_BillBoard.gameObject.SetActive(true); if (m_isMyCharacter) { m_MyPlayerColor = Color.green; if (PlayerPrefs.HasKey("myName")) { NickName = PlayerPrefs.GetString("myName"); } else { NickName = "Runner"; } m_BillBoard.InitProfileSprite(null); } else { m_MyPlayerColor = color[idx]; m_BillBoard.SetName(Common.strName[Random.Range(0, Common.strName.Length)]); m_BillBoard.InitProfileSprite(Common.regionName[Random.Range(0, Common.regionName.Length)]); } m_BillBoard.SetColor(m_MyPlayerColor); }
private void OnStackInteractUsing(EntityUid uid, StackComponent stack, InteractUsingEvent args) { if (!args.Used.TryGetComponent <StackComponent>(out var otherStack)) { return; } if (!otherStack.StackTypeId.Equals(stack.StackTypeId)) { return; } var toTransfer = Math.Min(stack.Count, otherStack.AvailableSpace); RaiseLocalEvent(uid, new StackChangeCountEvent(stack.Count - toTransfer), false); RaiseLocalEvent(args.Used.Uid, new StackChangeCountEvent(otherStack.Count + toTransfer), false); var popupPos = args.ClickLocation; if (!popupPos.IsValid(EntityManager)) { popupPos = args.User.Transform.Coordinates; } switch (toTransfer) { case > 0: popupPos.PopupMessage(args.User, $"+{toTransfer}"); if (otherStack.AvailableSpace == 0) { args.Used.SpawnTimer( 300, () => popupPos.PopupMessage( args.User, Loc.GetString("comp-stack-becomes-full") ) ); } break; case 0 when otherStack.AvailableSpace == 0: popupPos.PopupMessage( args.User, Loc.GetString("comp-stack-already-full") ); break; } args.Handled = true; }
/// <summary> /// Try to use an amount of items on this stack. /// See <see cref="StackUseEvent"/> /// </summary> private void OnStackUse(EntityUid uid, StackComponent stack, StackUseEvent args) { // Check if we have enough things in the stack for this... if (stack.Count < args.Amount) { // Not enough things in the stack, so we set the output result to false. args.Result = false; } else { // We do have enough things in the stack, so remove them and set the output result to true. RaiseLocalEvent(uid, new StackChangeCountEvent(stack.Count - args.Amount), false); args.Result = true; } }
public override void Initialize() { base.Initialize(); Stack = Owner.GetComponent <StackComponent>(); }
// Really this should check the actual materials at play.. public static bool MaterialStackValidFor(ConstructionStepMaterial step, StackComponent stack) { return(StackTypeMap.TryGetValue((StackType)stack.StackType, out var should) && should == step.Material); }
private void OnStackCountChanged(EntityUid uid, StackComponent component, StackCountChangedEvent args) { // Dirty the UI now that the stack count has changed. component.DirtyUI(); }
public override void Process(Entity entity) { // // entity = Stack entities (there are 26 of them) // This process happens for every stack // StackComponent sc = entity.GetComponent <StackComponent>(); //Entity lastCardonStack = sc.CheckersInStack.LastOrDefault(); // // fan out is half size of the checker // switch (sc.FannedDirection) { case 0: fanOutDistannce = Vector2.Zero; break; case 1: fanOutDistannce = new Vector2(22f, 0); break; case 2: fanOutDistannce = new Vector2(-22f, 0); break; case 3: fanOutDistannce = new Vector2(0, -22f); //upwards break; case 4: fanOutDistannce = new Vector2(0, 22f); //downwards break; } // // if we have more than 10 checkers in this Stack, make the fanout value smaller so they all fit // if (sc.CheckersInStack.Count > 10) { switch (sc.FannedDirection) { case 3: fanOutDistannce = new Vector2(0, -12f); break; case 4: fanOutDistannce = new Vector2(0, 12f); break; } } int ind = 0; //checker index in stack for (int i = 0; i < sc.CheckersInStack.Count; i++) { Entity checkerEntity = sc.CheckersInStack[i]; //get checker Vector2 stackPos = entity.Transform.Position; //get location of the stack (doesn't change) // // The offset value upward or downward // if (sc.FannedDirection == 4) //downward { stackPos.Y -= 123 - 25; //initial location } else { stackPos.Y += 123 - 25; //upward } // //znznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznzn // Checker position determined by stack position with offset values //znznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznzn // checkerEntity.Transform.Position = stackPos + fanOutDistannce * new Vector2(ind, ind); // // Get the CheckerComponent & its sprite shape // (we don't need to do this every frame but then the checkers won't look pretty) // var cComp = checkerEntity.GetComponent <CheckerComponent>(); //CheckerComponent has the data var renderComp = checkerEntity.GetComponent <SpriteRenderer>(); //sprite image of the checker // // -1 is first layer to display and -9 is last layer to display // renderComp.RenderLayer = ind * -100; renderComp.Sprite = cComp.CheckerFace; ind += 1; } }
public override void Process(Entity entity) { // // Mouse events are processed for White (human) player // hint: After white player clicks on "Dice Roll" then its his turn // MainGameScene = entity.Scene as MainScene; //hand entity belongs to MainScene if (MainGameScene.GameEnded) { MainGameScene.EndOfGame(); return; } if (!MainGameScene.WhiteCanMove) //Can white move? { return; } // // Mouse working area (find if it clicks on anything) // var _mouseCollider = entity.GetComponent <BoxCollider>(); CurrentMouse = Mouse.GetState(); // // Current location of the mouse // entity.Transform.Position = Scene.Camera.ScreenToWorldPoint(new Vector2(CurrentMouse.Position.X, CurrentMouse.Position.Y)); MousePos = new Vector2(CurrentMouse.Position.X, CurrentMouse.Position.Y); // // Check the mouse input action // if (Input.LeftMouseButtonPressed) { MainGameScene.Dragging = false; // // If mouse click is not colliding with anything (do nothing) // if (!_mouseCollider.CollidesWithAny(out CollisionResult collisionResult)) { return; } gameStack = collisionResult.Collider.Entity; if (MainGameScene.TestGraveYardForCheckers(24) > 0) //if true, then graveyard checkers go first { if (!MainGameScene.WhiteCanMoveFromGraveYard()) { MainGameScene.WhiteCanMove = false; return; } // // Test to see if White can move from graveyard, if not then set Whitecanmove to false // gameStack = MainGameScene.GameStacks[24]; //automatically, use checkers from White graveyard stack } // // Collided entity is a stack of checkers // Test it to be empty or black checkers (do nothing) // StackComponent sc = gameStack.GetComponent <StackComponent>(); if (sc == null) { return; //no stack of checkers } if (sc.CheckersInStack.Count == 0) { return; //empty stack of checkers } // // black checers tag are < 0 and white are > 0 // if (sc.CheckersInStack[0].Tag < 0) { return; //test first checker, if black checker leave } //znznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznzn // Human player has grabbed a White checker //znznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznznzn MainGameScene.Dragging = true; Entity chkerDragEntity = sc.CheckersInStack[0]; //checker being dragged is saved sc.CheckersInStack.RemoveAt(0); //checker being dragges is Removed from original stack DragComponent dc = new DragComponent(); dc.FromStack = gameStack; //remember original stack chkerDragEntity.AddComponent <DragComponent>(dc); //add component so CheckerDragSystem can see it MainGameScene.CheckerBeingDragged = chkerDragEntity; //make sure we know, the checker being dragged } if (Input.LeftMouseButtonReleased) { // // Find the collider entity that checker is being dropped // if (!_mouseCollider.CollidesWithAny(out CollisionResult collisionResult)) { if (MainGameScene.Dragging) { MainGameScene.DropChecker2PreviousPosition(); } return; } // // We have dropped on top of a Stack // gameStack = collisionResult.Collider.Entity; if (MainGameScene.Dragging) { // // You can't drop White checkers on graveyard stacks //if (stack.Tag > 23) //{ // MainGameScene.DropChecker2PreviousPosition(); // MainGameScene.Dragging = false; // return; //} // // Drop location must either be Empty or have one or more White checkers, or be collector // StackComponent sc = gameStack.GetComponent <StackComponent>(); singleBlack = ((sc.CheckersInStack.Count() == 1) && (sc.CheckersInStack[0].Tag < 0)); //single black stackIsEmpty = (sc.CheckersInStack.Count == 0); if (stackIsEmpty) { stackIsWhite = true; } else { stackIsWhite = (sc.CheckersInStack[0].Tag > 0); } if (stackIsEmpty || stackIsWhite || singleBlack) { MainGameScene.DropChecker2NewPosition(gameStack); } else { MainGameScene.DropChecker2PreviousPosition(); } MainGameScene.Dragging = false; } } }