예제 #1
0
        private ITransferable Drop(IDropper dropper, Guid objId)
        {
            var obj = State.FindObject(objId);

            if (obj == null)
            {
                throw new BadActionException($"Unit {dropper} cannot give away a non-existing object {obj}");
            }

            if (obj is ITransferable transferable)
            {
                if (transferable.Owner != ((Unit)dropper).Id)
                {
                    throw new BadActionException($"Unit {dropper} cannot give away the object {obj} because it does not posses it");
                }

                if (!dropper.Drop(transferable))
                {
                    return(null);
                }

                transferable.Drop();
                obj.Move(((Unit)dropper).Location);
            }
            else
            {
                throw new BadActionException($"Unit {dropper} cannot drop a non-transferable object {obj}");
            }

            return(transferable);
        }
예제 #2
0
        public void DropReward(IDropper dropper)
        {
            Vector3 dropPosition           = dropper.GetDropPosition();
            List <DropChancePair> dropList = dropper.GetDropList();

            int roll  = UnityEngine.Random.Range(0, dropper.GetDropChanceRange() + 1); // not accurate
            int accum = 0;

            foreach (DropChancePair dcp in dropList)
            {
                accum += dcp.weightage;
                if (roll <= accum)
                {
                    dropItem(dropPosition, dcp.dropPrefab);
                    break;
                }
            }
        }
예제 #3
0
        private void GiveAway(IDropper donor, GiveAction action)
        {
            var recipient = State.FindObject(action.Recepient);

            if (!(recipient is IReceiver receiver) || !IsAdjacent((Unit)donor, recipient))
            {
                Drop(donor, action.ObjectId);   //Transfer to a non-receiver is a Drop
                return;
            }

            var transferable = Drop(donor, action.ObjectId);

            //Will be null if Dropper could not drop an item
            if (transferable == null)
            {
                return;
            }

            if (receiver.Receive(transferable))
            {
                transferable.TransferTo(recipient.Id);
            }
            //else the object stays on the ground
        }
예제 #4
0
 private void ExecuteDrop(IDropper dropper, DropAction action)
 {
     Drop(dropper, action.ObjectId);
 }