Example #1
0
 protected virtual void VirtualUsing(UseContext args)
 {
     if (m_UseTime > 0.2f)
     {
         args.m_Done = true;
     }
 }
Example #2
0
        void DowseClosest(UseContext args)
        {
            m_DowsedPosition = Vector3.zero;

            var     proxyworld      = TwoDee.ComponentList.GetFirst <TwoDee.ProxyWorld>();
            var     stuff           = proxyworld.GetGameObjectsOrProxies("oreteleport");
            Vector3 closestPosition = Vector3.zero;
            var     positions       = new List <Vector3>();

            foreach (var ob in stuff)
            {
                positions.Add(ob.Position);
            }

            var closestDistance = 9999999.0f;

            foreach (var pos in positions)
            {
                var delta = (pos - args.m_OriginPos);
                if (delta.magnitude < 200 && delta.magnitude < closestDistance)
                {
                    closestDistance  = delta.magnitude;
                    m_DowsedPosition = pos;
                }
            }
        }
Example #3
0
            public override bool ConsumeJumpBoots(StateArgs args)
            {
                var pargs      = args as PlanetsStateArgs;
                var useContext = new UseContext()
                {
                    m_DeltaTime   = Time.fixedDeltaTime,
                    m_Inventory   = pargs.m_PlanetsCharacter.InventoryEquipment,
                    m_Inventories = new Inventory[] { pargs.m_PlanetsCharacter.Inventory, pargs.m_PlanetsCharacter.InventoryEquipment }
                };

                for (int i = 0; i < pargs.m_PlanetsCharacter.InventoryEquipment.Count; i++)
                {
                    useContext.m_Entry = pargs.m_PlanetsCharacter.InventoryEquipment.GetSlot(i);
                    if (useContext.m_Entry == null)
                    {
                        continue;
                    }
                    useContext.m_InventorySlot = i;
                    var slotEntry = pargs.m_PlanetsCharacter.InventoryEquipment.GetEntryInSlot(i);
                    if (slotEntry.m_Item.JumpBoost(useContext))
                    {
                        EasySound.Play("thrust", args.m_GameObject);
                        return(true);
                    }
                }

                return(false);
            }
Example #4
0
 public override void Use(UseContext args)
 {
     base.Use(args);
     DowseClosest(args);
     m_TimeBought += 5.0f;
     UseQuantity(args, 1);
 }
Example #5
0
 public override void Selected(UseContext args)
 {
     m_Rotated        = 0;
     m_ValidPlacement = false;
     m_Ghost          = GameObject.Instantiate(GhostPrefab, args.m_TargetPos, Quaternion.identity);
     SetupGhost();
 }
Example #6
0
        public override void Use(UseContext args)
        {
            float   power = args.m_Entry.DbEntry.GetCombinedPropFloat("power", args.m_Entry.m_Properties);
            Vector3 dir   = args.m_TargetPos - args.m_OriginPos;
            // Shoot a ray from the origin to the target to see the point we will 'dig' at.
            RaycastHit hitInfo;

            bool additive = false;

            // Only carving for now
            //additive = args.m_Secondary;

            //if (Physics.Raycast(new Ray(args.m_OriginPos, dir.normalized), out hitInfo, 2.0f, GameObjectExt.GetLayerMask("Ground")))
            {
                TwoDee.EasySound.Play("dig", args.m_OriginPos);

                foreach (var vg in TwoDee.ComponentList.GetCopiedListOfType <TwoDee.VoxelGenerator>())
                {
                    vg.ModifyCircle(power, additive, ClampedPos(args), DigRadius);
                }

                ChargeTimeCost();
                UseQuantity(args, 1);
            }
        }
Example #7
0
        public override void Use(UseContext args)
        {
            if (m_CanRotate && args.m_ButtonPressed == 1)
            {
                m_Rotated = (m_Rotated + 30) % 360;
                return;
            }
            if (!m_ValidPlacement)
            {
                TwoDee.EasySound.Play("uierror", args.m_OriginPos);
                return;
            }
            if (m_Ghost == null || !m_Ghost)
            {
                return;
            }
            var pos    = ClampedPos(args);
            var rot    = m_Ghost.transform.rotation;
            var newObj = GameObject.Instantiate(m_StructurePrefab, pos, rot);
            var bp     = newObj.GetComponent <IBlueprintPlaced>();

            if (bp != null)
            {
                bp.BlueprintPlaced(new BlueprintPlaceArgs(gameObject));
            }
            TwoDee.EasySound.Play("uiplacement", args.m_TargetPos);

            OnPlaced(args, newObj);
            NetworkServer.Spawn(newObj);


            UseQuantity(args, 1);
        }
Example #8
0
        protected override void VirtualUsing(UseContext args)
        {
            if (args.m_ButtonHeld == -1 || m_Tractor == null)
            {
                args.m_Done = true;
            }
            if (m_Tractor == null)
            {
                return;
            }

            if (m_TractorEffect == null)
            {
                m_TractorEffect = GameObject.Instantiate <GameObject>(m_TractorEffectPrefab, Vector3.zero, Quaternion.identity);
            }

            var rb = m_Tractor.GetComponent <Rigidbody>();

            if (rb != null)
            {
                TwoDee.EasySound.Play("tractorbeam", args.m_TargetPos);

                float scaleForce   = 500.0f;
                float maxForceRope = 200.0f;
                float maxForce     = 12.0f;
                if (m_UsingStrongBeam && UseEnergy(args, args.m_DeltaTime * 1.0f))
                {
                    maxForce   = 16.0f;
                    scaleForce = 600.0f;
                }

                var target      = args.m_TargetPos; //MaxUseDistance
                var originDelta = (target - args.m_OriginPos);
                if (originDelta.magnitude > MaxUseDistance)
                {
                    target = args.m_OriginPos + (originDelta).normalized * MaxUseDistance;
                }


                var currentOffset_ws = m_Tractor.transform.TransformPoint(m_TractorLocalOffset);
                // Predict where tractor will go and use that point
                float predictionDt = 0.2f;
                currentOffset_ws += m_Tractor.GetComponent <Rigidbody>().velocity *predictionDt;
                var delta         = (target - currentOffset_ws);
                var desiredForce  = scaleForce * delta;
                var maxForceToUse = (TractorRopeLink != null) ? maxForceRope : maxForce;
                if (desiredForce.magnitude > maxForceToUse)
                {
                    desiredForce = desiredForce.normalized * maxForceToUse;
                }
                rb.AddForceAtPosition(desiredForce, currentOffset_ws);
                // Conform rotation if needed
                var oldEuler = rb.gameObject.transform.rotation.eulerAngles;
                oldEuler.x = oldEuler.y = 0.0f;
                rb.gameObject.transform.rotation = Quaternion.Euler(oldEuler);

                m_TractorEffect.GetComponent <TractorPreview>().UpdateTractor(args.m_OriginPos, target, currentOffset_ws);
            }
        }
Example #9
0
 public void UseQuantity(UseContext args, int amount)
 {
     args.m_Entry.m_Count -= amount;
     if (args.m_Entry.m_Count == 0)
     {
         args.m_Inventory.SetSlot(args.m_InventorySlot, null);
     }
 }
Example #10
0
        public override void Selected(UseContext args)
        {
            m_ValidPlacement = true;
            base.Selected(args);
            float fudgeScale            = 0.9f;
            float radiusDoubleWithScale = (2.0f * DigRadius) * fudgeScale;

            m_Ghost.transform.localScale = new Vector3(radiusDoubleWithScale, radiusDoubleWithScale, radiusDoubleWithScale);
        }
Example #11
0
        public Vector3 ClampedPos(UseContext args)
        {
            //var pos = args.m_TargetPos + m_PlacementOffset;
            float dist = args.DirectionDistance;

            dist = Mathf.Min(dist, m_PlacementRange);

            return(args.m_OriginPos + args.Direction * dist + m_PlacementOffset);
        }
Example #12
0
        public override bool JumpBoost(UseContext args)
        {
            if (UseEnergy(args, args.m_DeltaTime * 4.0f))
            {
                return(true);
            }

            return(false);
        }
Example #13
0
 protected override void VirtualEndUse(UseContext args)
 {
     // If dragging a rope try to connect it to something
     if (m_Tractor != null && TractorRopeLink != null)
     {
         ConnectToRope(args);
     }
     DestroyImmediate(m_TractorEffect);
 }
Example #14
0
        public override void Use(UseContext args)
        {
            float power = args.m_Entry.DbEntry.GetCombinedPropFloat("power", args.m_Entry.m_Properties);

            if (args.m_ClickedTarget)
            {
                // Harvest target
                UseDurability(args, 5.0f);
            }
        }
Example #15
0
        public Vector3 ClampedPos(UseContext args)
        {
            var   pos  = args.m_TargetPos + m_PlacementOffset;
            float dist = args.DirectionDistance;

            // Place it close enough that it's not really possible to create really ugly notches from intersecting circles
            dist = Mathf.Min(dist, m_DigRadius * 0.85f);

            return(args.m_OriginPos + args.Direction * dist);
        }
Example #16
0
        public override void UpdateSelected(UseContext args)
        {
            m_Ghost.transform.position = args.m_TargetPos + m_PlacementOffset;
            Vector3 userUpDir = args.m_ItemUserGameObject.transform.rotation * Vector3.up;

            m_Ghost.transform.rotation = Quaternion.FromToRotation(Vector3.up, userUpDir) * Quaternion.Euler(0.0f, 0.0f, m_Rotated);

            foreach (var renderer in m_Ghost.GetComponentsInSelfOrChildren <Renderer>())
            {
                renderer.material = m_ValidPlacement ? args.m_GhostMaterialGood : args.m_GhostMaterialBad;
            }
        }
Example #17
0
        public override void Use(UseContext args)
        {
            var playerPos = args.m_OriginPos;
            var closest   = TwoDee.ComponentList.GetClosest <Rope>(playerPos);

            if (closest != null && (closest.transform.position - playerPos).magnitude < 2.0f)
            {
                if (closest.EnterWinching())
                {
                    UseQuantity(args, 1);
                }
            }
        }
Example #18
0
        protected override void VirtualUsing(UseContext args)
        {
            float minUseTime = MinUseTime;

            if (m_UseTime > minUseTime)
            {
                args.m_ShowTrajectory.m_Value = m_ThrowMin + (m_ThrowMax - m_ThrowMin) * ThrowIntensity;

                if (args.m_ButtonHeld == -1)
                {
                    args.m_Done = true;
                }
            }
        }
Example #19
0
 protected override void VirtualEndUse(UseContext args)
 {
     if (m_DidSomething)
     {
         if (UnityEngine.Random.value < m_BreakChance)
         {
             if (m_BreakParticlePrefab != null)
             {
                 GameObject.Instantiate <GameObject>(m_BreakParticlePrefab, m_Weapon.transform.position, Quaternion.identity);
             }
             UseQuantity(args, 1);
         }
     }
     DestroyImmediate(m_Weapon);
 }
Example #20
0
        public bool UseEnergy(UseContext args, float amount)
        {
            if (args.m_Entry.DrainEnergy(amount, true))
            {
                return(true);
            }
            foreach (var inv in args.m_Inventories)
            {
                if (inv.DrainEnergy(amount, true, true))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #21
0
        protected override void VirtualBeginUse(UseContext args)
        {
            m_Weapon = CreateWeapon(args.m_OriginPos, args.m_TargetPos);
            TwoDee.EasySound.Play("swing", gameObject);

            // What stuff did we smack
            var didHitAlready = new Dictionary <GameObject, bool>();
            var weaponLoc     = m_Weapon.transform.position;

            m_DidSomething = false;
            foreach (var hit in Physics.OverlapSphere(weaponLoc, 1.0f))
            {
                var goSelf = hit.GetComponent <Collider>().gameObject;
                var go     = goSelf.GetTopParent();

                if (go == m_Weapon)
                {
                    continue;
                }
                if (go == args.m_ItemUserGameObject)
                {
                    continue;
                }


                if (!didHitAlready.ContainsKey(go))
                {
                    didHitAlready[go] = true;

                    if (TwoDee.Health.ApplyDamageIfEnemy(go, args.m_ItemUserGameObject, new TwoDee.DamageArgs(m_MeleeDamage, TwoDee.DamageType.Physical, args.m_ItemUserGameObject, weaponLoc)))
                    {
                        m_DidSomething = true;
                    }

                    if (m_ChopAmount > 0.0f)
                    {
                        var tree = go.GetComponentInSelfOrParents <Tree>();
                        if (tree != null)
                        {
                            ChargeTimeCost();
                            tree.Chop(m_ChopAmount, args.m_OriginPos);
                            m_DidSomething = true;
                        }
                    }
                }
            }
        }
Example #22
0
        protected override void VirtualFixedUpdateControl()
        {
            if (m_DeferredItemUse != null)
            {
                /* Only for items that lock you in place
                 * m_Args.clear();
                 * // Face towards usage direction
                 * Vector3 delta = m_DeferredItemUse.m_TargetPos - m_DeferredItemUse.m_OriginPos;
                 * m_Args.m_Move = transform.InverseTransformDirection(delta).normalized * 0.01f;
                 */

                bool done    = false;
                bool destroy = false;

                var itemObject = m_DeferredItemUse.m_ItemObject;

                // Cancel if we fell while animation is playing
                bool canceled = (itemObject.RequiresStanding && !(CurrentState is TwoDee.ThirdPersonCharacter.WalkingState));

                itemObject.Using(m_DeferredItemUse);
                if (m_DeferredItemUse.m_Done)
                {
                    itemObject.Use(m_DeferredItemUse);
                    if (m_DeferredItemUse.m_Destroy)
                    {
                        destroy = true;
                    }
                    done = true;
                }

                if (canceled || done)
                {
                    m_DeferredItemUse.m_Canceled = canceled;
                    itemObject.EndUse(m_DeferredItemUse);

                    if (destroy)
                    {
                        Inventory.DropInventory(m_DeferredItemUse.m_InventorySlot);
                    }
                    m_DeferredItemUse = null;
                }
            }
            else if (m_ItemUseCooldown > 0.0f)
            {
                m_ItemUseCooldown -= m_Args.DeltaTime;
            }
        }
Example #23
0
        public override void Use(UseContext args)
        {
            // Transfer 10 charge into thing next to us if we have it
            int mySlot    = args.m_InventorySlot;
            var myEntry   = args.m_Inventory.GetSlot(mySlot);
            var nextEntry = args.m_Inventory.GetSlot(mySlot + 1);

            if (nextEntry != null)
            {
                float myEnergy      = myEntry.GetProperty("energy");
                float amountCharged = nextEntry.ChargeEnergy(Mathf.Min(myEnergy, 10.0f));
                if (amountCharged > 0.0f)
                {
                    myEntry.ChargeEnergy(-amountCharged);
                }
            }
        }
Example #24
0
        public void UseDurability(UseContext args, float amount)
        {
            if (null == args.m_Entry.m_Properties || !args.m_Entry.m_Properties.ContainsKey("durability"))
            {
                return;
            }
            float oldAmount;

            if (float.TryParse(args.m_Entry.m_Properties["durability"], out oldAmount))
            {
                oldAmount -= amount;
                args.m_Entry.m_Properties["durability"] = "" + oldAmount;
                if (oldAmount <= 0.0f)
                {
                    args.m_Destroy = true;
                }
            }
        }
Example #25
0
        public override void OnPlaced(UseContext args, GameObject newObj)
        {
            if (m_TeleporterEndPrefab == null)
            {
                return;
            }

            // Find base, place somewhere near
            var homeBase = TwoDee.ComponentList.GetFirst <HomeBase>();

            /*
             * var endPos = (homeBase ? homeBase.transform.position : Vector3.zero) + Vector3.left * 10.0f;
             * var otherEnd = GameObject.Instantiate<GameObject>(m_TeleporterEndPrefab, endPos, Quaternion.identity);
             */

            var newObjTeleporter = newObj.GetComponent <Teleporter>();

            newObjTeleporter.ConnectToOther(homeBase.gameObject);
        }
Example #26
0
        public void FinallyThrow(UseContext args)
        {
            var pos = args.m_OriginPos;
            var dir = args.Direction;

            TwoDee.EasySound.Play(m_UseSound, args.m_OriginPos);
            var thrown = TwoDee.ThrownWeapon.DoThrow(m_ThrownPrefab, pos, dir, args.m_ItemUserGameObject, args.m_ShowTrajectory.m_Value, ThrowIntensity, m_ThrowRange, m_Spin, m_MinDamage, m_MaxDamage);

            if (!m_Spin)
            {
                thrown.m_FaceDir = true;
            }

            if (m_TimedBomb > 0.0f)
            {
                thrown.m_TimedBomb = m_TimedBomb;
            }

            UseQuantity(args, 1);
        }
Example #27
0
        public override void UpdateSelected(UseContext args)
        {
            base.UpdateSelected(args);

            var clampedPos = ClampedPos(args);

            // For blueprint, we can only place nearby us.
            m_Ghost.transform.position = clampedPos;

            int consideredGround = (GameObjectExt.GetLayerMask("Ground")) | (GameObjectExt.GetLayerMask("StructurePlatform"));

            // Should be clear to the target as well
            var        origin = args.m_OriginPos;
            var        delta  = args.m_TargetPos - args.m_OriginPos;
            RaycastHit hitInfo;

            m_ValidPlacement = m_GhostTT.CollidingObjects.ToList().Count == 0;
            if (Physics.Raycast(origin, delta.normalized, out hitInfo, delta.magnitude, consideredGround))
            {
                // m_ValidPlacement = false;
            }
        }
Example #28
0
        void ConnectToRope(UseContext args)
        {
            var ropeLinkPos = TractorRopeLink.gameObject.transform.position;

            foreach (Rigidbody body in GameObjectExt.GetNearbyObjects <Rigidbody>(ropeLinkPos, 0.7f,
                                                                                  GameObjectExt.GetLayerMask("Objects") | GameObjectExt.GetLayerMask("StructurePlatform") | GameObjectExt.GetLayerMask("Structure")

                                                                                  ))
            {
                var   go = body.gameObject;
                float ps = 322.0f;
                float mf = 322.0f;
                ps = mf = 1000.0f;
                float pd = 111.0f;

                var hj = CreateJoint(body, m_Tractor.GetComponent <Rigidbody>(), ps, mf, pd);
                // ore always connects in the center
                if (go.name.ToLower().Contains("ore"))
                {
                    hj.autoConfigureConnectedAnchor = false;
                    hj.connectedAnchor = Vector3.zero;
                    hj.targetPosition  = Vector3.zero;
                }
                else
                {
                    hj.autoConfigureConnectedAnchor = false;
                    hj.anchor         = go.transform.InverseTransformPoint(args.m_TargetPos);
                    hj.targetPosition = Vector3.zero;
                }

                if (TractorRopeLink.ConnectJoint(hj))
                {
                    return;
                }
            }

            // Couldn't connect, see if we assume it was a refund
            TractorRopeLink.m_Rope.CheckRefund(TractorRopeLink);
        }
Example #29
0
        public override void Use(UseContext args)
        {
            if (args.m_Secondary)
            {
                m_Grappling = !m_Grappling;
                return;
            }

            var goRope = GameObject.Instantiate <GameObject>(m_RopePrefab, args.m_OriginPos, Quaternion.identity);

            foreach (var rope in goRope.GetComponents <Rope>())
            {
                var  direction = args.Direction;
                bool grappling = m_Grappling;
                //@TEMP not sure if want to use this charging or not

                TwoDee.EasySound.Play("swing", gameObject);
                var speed = 1.0f * args.m_ShowTrajectory.m_Value;
                rope.StartUnravel(grappling, direction, speed, m_RopeLinks, args.GetItemName());
            }

            UseQuantity(args, 1);
        }
Example #30
0
        public bool TryUse(int slot, UseContext args)
        {
            if (m_ItemUseCooldown > 0.0f)
            {
                return(false);
            }
            if (m_DeferredItemUse != null)
            {
                return(false);
            }
            var entry = slot != -1 ? Inventory.GetSlot(slot) : null;

            if (null == entry)
            {
                return(false);
            }
            var selectedItem = Inventory.GetEntryInSlot(slot);

            var itemObject = args.GetItemObject(args.m_Secondary);

            if (itemObject.RequiresStanding && !(CurrentState is TwoDee.ThirdPersonCharacter.WalkingState))
            {
                return(false);
            }

            m_DeferredItemUse         = args;
            m_DeferredItemUse.m_Error = false;
            itemObject.BeginUse(m_DeferredItemUse);

            if (m_DeferredItemUse.m_Error)
            {
                TwoDee.EasySound.Play("uierror", args.m_OriginPos);
                return(false);
            }
            return(true);
        }