コード例 #1
0
        public float GetArea()
        {
            var firstEdgeLength  = VectorService.NodesToDirection(Edges[0].NodeA, Edges[0].NodeB).magnitude;
            var secondEdgeLength = VectorService.NodesToDirection(Edges[1].NodeA, Edges[1].NodeB).magnitude;

            return(firstEdgeLength * secondEdgeLength);
        }
コード例 #2
0
ファイル: Line.cs プロジェクト: Szuszi/CityGenerator-Unity
        public Line(Node onePoint, Node otherPoint)
        {
            BaseNode     = onePoint;
            NormalVector = VectorService.NodesToNormal(onePoint, otherPoint);

            if (NormalVector.magnitude == 0)
            {
                Debug.Log($"first Node: [{onePoint.X}|{onePoint.Y}] " +
                          $"other Node: [{otherPoint.X}|{otherPoint.Y}] ");
                throw new ArgumentException("Normal cannot be null", nameof(NormalVector));
            }
        }
コード例 #3
0
ファイル: DrawOrbits.cs プロジェクト: Amer2005/GravityTest
    public void DrawOrbitStart()
    {
        gravityGameObjects = GameObject.FindGameObjectsWithTag("GravityObject");
        vectorUtilities    = new VectorUtilities();
        vectorService      = new VectorService();

        FocusGameObject = gameView.FocusGameObject;

        GenerateGravityObjects();

        DrawOrbit();
    }
コード例 #4
0
        public void VectorService_Filter_Should_Return_A_Set_With_Only_A_Zero_When_Vector_Contains_Zero_Elements()
        {
            var service = new VectorService();
            var vector  = new List <int>();

            CollectionAssert.AreEqual(
                expected: new List <int> {
                0
            },
                actual: service.Filter(vector).ToList(),
                message: "The result is not as expected");
        }
コード例 #5
0
        private async Task OnTick()
        {
            try
            {
                var player         = PlayerPed.Ped;
                var pid            = PlayerPed.PedId;
                var playerLocation = PlayerPed.PlayerCoords;
                var firstPed       = GameWorld.FindFirstPed();
                var nextPed        = GameWorld.FindNextPed(firstPed.Handle);
                do
                {
                    // get ped coords
                    var pedPos          = nextPed.Entity.PedCoords;
                    var distanceFromPed = VectorService.DistanceBetweenVectors(pedPos, PlayerPed.PlayerCoords);
                    if (distanceFromPed < 3)
                    {
                        if (!PlayerPed.IsAnyVehicle)
                        {
                            if (nextPed.Entity.DoesEntityExist)
                            {
                                if (!nextPed.Entity.IsPedDeadOrDying)
                                {
                                    if (nextPed.Entity.PedType != 28 && !nextPed.Entity.IsPlayer)
                                    {
                                        pedPosition = nextPed.Entity.PedCoords;
                                        if (nextPed.Entity.IsNotPlayerPed &&
                                            nextPed.Entity.EntityId != oldPed && ControlsService.EWasPressed())
                                        {
                                            // set old ped entityId
                                            oldPed = nextPed.Entity.EntityId;
                                            nextPed.Entity.SetEntityAsMission();
                                            nextPed.Entity.ClearTasks();
                                            nextPed.Entity.Freeze();
                                            nextPed.Entity.StandStill();
                                            TriggerEvent(Strings.SellingDrugsEventName, nextPed.Entity);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    nextPed = GameWorld.FindNextPed(firstPed.Handle);
                } while (nextPed.Result);
                API.EndFindPed(firstPed.Handle);
            }
            catch (Exception e)
            {
                Debug.WriteLine($"Error Selling service : {e.Message}");
            }
            await Delay(100);
        }
コード例 #6
0
        public void VectorService_Filter_Should_Return_A_Set_Of_Even_Numbers_And_A_Count_Of_This_Numbers_Got_From_Vector_Parameter()
        {
            var service = new VectorService();
            var vector  = new List <int> {
                1, 2, 3, 4, 5, 6, 7, 8
            };

            CollectionAssert.AreEqual(
                expected: new List <int> {
                2, 4, 6, 8, 4
            },
                actual: service.Filter(vector).ToList(),
                message: "The result is not as expected");
        }
コード例 #7
0
        public Line GetCutLine(System.Random rand)
        {
            var firstEdgeLength  = VectorService.NodesToDirection(Edges[0].NodeA, Edges[0].NodeB).magnitude;
            var secondEdgeLength = VectorService.NodesToDirection(Edges[1].NodeA, Edges[1].NodeB).magnitude;
            var longerEdge       = firstEdgeLength > secondEdgeLength ? Edges[0] : Edges[1];

            Vector2 nodeAToB    = VectorService.NodesToDirection(longerEdge.NodeA, longerEdge.NodeB);
            int     randomValue = rand.Next(0, 4);
            float   offsetToUse = 0.3f + 0.1f * randomValue;

            var middlePoint = new Node
                              (
                (longerEdge.NodeA.X + nodeAToB.x * offsetToUse),
                (longerEdge.NodeA.Y + nodeAToB.y * offsetToUse)
                              );

            return(new Line(middlePoint, nodeAToB));
        }
コード例 #8
0
    public void Load(SmartPentagram pentagram, float radius, float letterSize)
    {
        Debug.Log("Scroll: Load. Pentagram is null: " + (pentagram == null));
        _pentagram = pentagram;

        int   nLetters         = pentagram.Letters().Length;
        float turningAngle     = 2 * Mathf.PI / nLetters;
        float stepVectorLength = 2 * radius * Mathf.Sin(turningAngle / 2);

        Debug.Log("Radius: " + radius + "\nStep: " + stepVectorLength);

        Vector2 letterPosition = new Vector2(0, radius);
        Vector2 stepVector     = new Vector2(0, -stepVectorLength);

        VectorService.RotateVector(ref stepVector, (turningAngle - Mathf.PI) / 2);

        Debug.Log("Going to place " + nLetters + "letters.");
        _pentaLetters = new PentaLetter[nLetters];
        for (int i = 0; i < nLetters; i++)
        {
            Debug.Log("Placing letter №" + i + ": " + pentagram.Letters()[i]);
            _pentaLetters[i] = _pool.GetLetter();
            _pentaLetters[i].Construct(pentagram.Letters()[i], nLetters);


            RectTransform rt = _pentaLetters[i].GetComponent <RectTransform>();
            rt.SetParent(this.transform);


            rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, letterSize);
            rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, letterSize);

            rt.anchoredPosition3D = new Vector3(letterPosition.x, letterPosition.y, _letterZ);
            letterPosition        = letterPosition + stepVector;


            _pentaLetters[i].AddDragEndedCallback(TryActivate);
            _pentaLetters[i].AddLetterSelectedCallback(SelectLetter);

            VectorService.RotateVector(ref stepVector, turningAngle);
        }
    }
コード例 #9
0
        public Edge GetCutEdge()
        {
            var firstEdgeLength  = VectorService.NodesToDirection(Edges[0].NodeA, Edges[0].NodeB).magnitude;
            var secondEdgeLength = VectorService.NodesToDirection(Edges[1].NodeA, Edges[1].NodeB).magnitude;
            var longerEdge       = firstEdgeLength > secondEdgeLength ? Edges[0] : Edges[1];
            var otherLongerEdge  = firstEdgeLength > secondEdgeLength ? Edges[2] : Edges[3];

            var middlePoint = new Node
                              (
                (longerEdge.NodeA.X + longerEdge.NodeB.X) / 2.0f,
                (longerEdge.NodeA.Y + longerEdge.NodeB.Y) / 2.0f
                              );

            var otherMiddlePoint = new Node
                                   (
                (otherLongerEdge.NodeA.X + otherLongerEdge.NodeB.X) / 2.0f,
                (otherLongerEdge.NodeA.Y + otherLongerEdge.NodeB.Y) / 2.0f
                                   );

            return(new Edge(middlePoint, otherMiddlePoint));
        }
コード例 #10
0
        public void ApplyEffects(NWCreature user, NWItem item, NWObject target, Location targetLocation, CustomData customData)
        {
            DateTime now            = DateTime.UtcNow;
            DateTime unlockDateTime = now;

            if (string.IsNullOrWhiteSpace(GetLocalString(user, "GRENADE_UNLOCKTIME")))
            {
                unlockDateTime = unlockDateTime.AddSeconds(-1);
            }
            else
            {
                unlockDateTime = DateTime.ParseExact(GetLocalString(user, "GRENADE_UNLOCKTIME"), "yyyy-MM-dd hh:mm:ss", CultureInfo.InvariantCulture);
            }
            //Console.WriteLine("IsValidTarget - Current Time = " + now.ToString("yyyy-MM-dd hh:mm:ss", CultureInfo.InvariantCulture));
            //Console.WriteLine("IsValidTarget - Unlocktime = " + unlockDateTime.ToString("yyyy-MM-dd hh:mm:ss", CultureInfo.InvariantCulture));
            //Console.WriteLine("IsValidTarget - DateTime.Compare = " + DateTime.Compare(unlockDateTime, now));

            // Check if we've passed the unlock date. Exit early if we have not.
            if (DateTime.Compare(unlockDateTime, now) > 0 || unlockDateTime > now)
            {
                string timeToWait = TimeService.GetTimeToWaitLongIntervals(now, unlockDateTime, false);
                //Console.WriteLine("IsValidTarget - That ability can be used in " + timeToWait + ".");
                SendMessageToPC(user, "That ability can be used in " + timeToWait + ".");
                return;
            }

            Effect impactEffect = null;
            var    spellId      = Spell.Invalid;
            string soundName    = null;
            int    perkLevel    = 1 + PerkService.GetCreaturePerkLevel(user, PerkType.GrenadeProficiency);
            int    skillLevel   = 5 + SkillService.GetPCSkillRank((NWPlayer)user, SkillType.Throwing);

            if (perkLevel == 0)
            {
                perkLevel += 1;
            }

            if (GetIsObjectValid(target) == true)
            {
                targetLocation = GetLocation(target);
            }
            string grenadeType = item.GetLocalString("TYPE");
            //Console.WriteLine("Throwing " + grenadeType + " grenade at perk level " + perkLevel);
            Location originalLocation = targetLocation;

            int roll = RandomService.D100(1);

            SendMessageToPC(user, roll + " vs. DC " + (100 - skillLevel));
            if (roll < (100 - skillLevel))
            {
                if (RandomService.D20(1) == 1)
                {
                    SendMessageToPC(user, "You threw... poorly.");
                    //targetLocation = VectorService.MoveLocation(targetLocation, GetFacing(user), (RandomService.D6(4) - 10) * 1.0f,
                    targetLocation = VectorService.MoveLocation(user.Location, RandomService.D100(1) + RandomService.D100(1) + RandomService.D100(1) + 60, RandomService.D4(2) * 1.0f,
                                                                RandomService.D100(1) + RandomService.D100(1) + RandomService.D100(1));
                    int count = 0;
                    while ((GetSurfaceMaterial(targetLocation) == 0 ||
                            LineOfSightVector(GetPositionFromLocation(targetLocation), GetPosition(user)) == false) &&
                           count < 10)
                    {
                        count         += 1;
                        targetLocation = VectorService.MoveLocation(user.Location, RandomService.D100(1) + RandomService.D100(1) + RandomService.D100(1) + 60, RandomService.D4(2) * 1.0f,
                                                                    RandomService.D100(1) + RandomService.D100(1) + RandomService.D100(1));
                    }
                }
                else
                {
                    SendMessageToPC(user, "Your throw was a bit off the mark.");
                    //targetLocation = VectorService.MoveLocation(targetLocation, GetFacing(user), (RandomService.D6(4) - 10) * 1.0f,
                    targetLocation = VectorService.MoveLocation(targetLocation, RandomService.D100(1) + RandomService.D100(1) + RandomService.D100(1) + 60, RandomService.D4(2) /*(RandomService.D6(4) - 10) */ * 1.0f,
                                                                RandomService.D100(1) + RandomService.D100(1) + RandomService.D100(1));
                    int count = 0;
                    while ((GetSurfaceMaterial(targetLocation) == 0 ||
                            LineOfSightVector(GetPositionFromLocation(targetLocation), GetPosition(user)) == false) &&
                           count < 10)
                    {
                        count         += 1;
                        targetLocation = VectorService.MoveLocation(targetLocation, RandomService.D100(1) + RandomService.D100(1) + RandomService.D100(1) + 60, RandomService.D4(2) /*(RandomService.D6(4) - 10) */ * 1.0f,
                                                                    RandomService.D100(1) + RandomService.D100(1) + RandomService.D100(1));
                    }
                }

                if (GetSurfaceMaterial(targetLocation) == 0 ||
                    LineOfSightVector(GetPositionFromLocation(targetLocation), GetPosition(user)) == false)
                {
                    targetLocation = originalLocation;
                }
            }

            switch (grenadeType)
            {
            case "FRAG":
                impactEffect = EffectVisualEffect(VisualEffect.Fnf_Fireball);
                // force a specific spell id (for projectile model) for this grenade.
                spellId   = Spell.Grenade10;
                soundName = "explosion2";
                break;

            case "CONCUSSION":
                impactEffect = EffectVisualEffect(VisualEffect.Vfx_Fnf_Sound_Burst_Silent);
                impactEffect = EffectLinkEffects(EffectVisualEffect(VisualEffect.Vfx_Fnf_Screen_Shake), impactEffect);
                spellId      = Spell.Grenade10;
                soundName    = "explosion1";
                break;

            case "FLASHBANG":
                impactEffect = EffectVisualEffect(VisualEffect.Vfx_Fnf_Mystical_Explosion);
                spellId      = Spell.Grenade10;
                soundName    = "explosion1";
                break;

            case "ION":
                impactEffect = EffectVisualEffect(VisualEffect.Vfx_Fnf_Electric_Explosion);
                spellId      = Spell.Grenade10;
                soundName    = "explosion1";
                break;

            case "BACTA":
                impactEffect = EffectVisualEffect(VisualEffect.Vfx_Fnf_Gas_Explosion_Nature);
                spellId      = Spell.Grenade10;
                //soundName = "explosion1";
                break;

            case "ADHESIVE":
                impactEffect = EffectVisualEffect(VisualEffect.Fnf_Dispel_Greater);
                spellId      = Spell.Grenade10;
                //soundName = "explosion1";
                break;

            case "SMOKE":
                impactEffect = null;
                spellId      = Spell.Grenade10;
                //soundName = "explosion1";
                break;

            case "BACTABOMB":
                impactEffect = null;
                spellId      = Spell.Grenade10;
                //soundName = "explosion1";
                break;

            case "INCENDIARY":
                impactEffect = null;
                spellId      = Spell.Grenade10;
                //soundName = "explosion1";
                break;

            case "GAS":
                impactEffect = null;
                spellId      = Spell.Grenade10;
                //soundName = "explosion1";
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(grenadeType));
            }

            if (spellId == 0)
            {
                // start 974 through 979 in spells.2da for grenades
                // lets randomly assign a projectile appearance for flavor?
                spellId = (Spell)(RandomService.D6(1) + 973);
            }

            float delay = GetDistanceBetweenLocations(user.Location, targetLocation) / 18.0f + 0.75f;

            delay += 0.4f; // added for animation
            user.ClearAllActions();
            //user.AssignCommand(() => _.ActionPlayAnimation(32));
            //user.DelayAssignCommand(() => _.ActionPlayAnimation(32), 0.0f);
            user.AssignCommand(() =>
            {
                ActionPlayAnimation(Animation.LoopingCustom12);
                ActionCastSpellAtLocation(spellId, targetLocation, MetaMagic.Any, true, ProjectilePathType.Ballistic, true);
                //ActionCastFakeSpellAtLocation(spellId, targetLocation, PROJECTILE_PATH_TYPE_BALLISTIC);
            });

            if (soundName != null)
            {
                user.DelayAssignCommand(() =>
                {
                    PlaySound(soundName);
                }, delay);
            }

            if (impactEffect != null)
            {
                user.DelayAssignCommand(() =>
                {
                    ApplyEffectAtLocation(DurationType.Instant, impactEffect, targetLocation);
                }, delay);
            }

            user.DelayAssignCommand(
                () =>
            {
                DoImpact(user, item, targetLocation, grenadeType, perkLevel, RadiusSize.Large, ObjectType.Creature);
            }, delay + 0.75f);


            perkLevel = PerkService.GetCreaturePerkLevel(user, PerkType.GrenadeProficiency);

            now = DateTime.UtcNow;
            DateTime unlockTime = now;

            if (perkLevel < 5)
            {
                unlockTime = unlockTime.AddSeconds(6);
            }
            else if (perkLevel < 10)
            {
                unlockTime = unlockTime.AddSeconds(3);
            }
            else
            {
                unlockTime = unlockTime.AddSeconds(2);
            }

            SetLocalString(user, "GRENADE_UNLOCKTIME", unlockTime.ToString("yyyy-MM-dd hh:mm:ss", CultureInfo.InvariantCulture));
            //Console.WriteLine("StartUseItem - Current Time = " + now.ToString("yyyy-MM-dd hh:mm:ss", CultureInfo.InvariantCulture));
            //Console.WriteLine("StartUseItem - Unlocktime Set To = " + unlockTime.ToString("yyyy-MM-dd hh:mm:ss", CultureInfo.InvariantCulture));
            if (user.IsCreature)
            {
                DurabilityService.RunItemDecay((NWPlayer)user, item, 1.0f);
            }
        }
コード例 #11
0
ファイル: Line.cs プロジェクト: Szuszi/CityGenerator-Unity
        private Node getRandomOtherNodeInLine()
        {
            Vector2 dirVector = VectorService.DirectionToNormal(NormalVector);

            return(new Node(BaseNode.X + dirVector.x, BaseNode.Y + dirVector.y));
        }
コード例 #12
0
ファイル: Line.cs プロジェクト: Szuszi/CityGenerator-Unity
 public Line CalculatePerpendicularLine(Node nodeToCross)
 {
     return(new Line(nodeToCross, VectorService.DirectionToNormal(NormalVector)));
 }
コード例 #13
0
    private void DrawCurve()
    {
        _lineRenderer.positionCount = 0;

        if (_lettersCount == 1)
        {
            return;
        }

        if (_lettersCount == 2)
        {
            _lineRenderer.positionCount = 2;
            _lineRenderer.SetPosition(0, _lettersPos[0]);
            _lineRenderer.SetPosition(1, _lettersPos[1]);
            return;
        }

        Vector3 prevDir = Vector3.zero;

        for (int segN = 1; segN < _lettersCount; segN++)
        {
            Vector3 curDir = Vector3.zero;

            Vector3 supportingPoint1 = Vector3.zero;
            Vector3 supportingPoint2 = Vector3.zero;

            Vector3 A = _lettersPos[segN - 1];
            Vector3 B = _lettersPos[segN];
            Vector3 C = (segN != _lettersCount - 1) ? _lettersPos[segN + 1] : _lettersPos[segN];


            Vector3 BA           = A - B;
            Vector3 BC           = C - B;
            float   angleBetween = Mathf.Deg2Rad * Vector3.SignedAngle(BC, BA, _rotationAxis);


            float rotationAngle = angleBetween;
            rotationAngle += (rotationAngle >= 0) ? Mathf.PI : -Mathf.PI;
            rotationAngle  = rotationAngle / 2;
            VectorService.RotateVector(ref BC, rotationAngle);

            curDir = BC.normalized;

            float lever1Length = _leversPercentage * BA.magnitude;
            if (lever1Length < _minLeverLength)
            {
                lever1Length = _minLeverLength;
            }

            float lever2Length = _leversPercentage * BC.magnitude;
            if (lever2Length < _minLeverLength)
            {
                lever2Length = _minLeverLength;
            }

            supportingPoint1 = A + ((-1) * lever1Length) * prevDir;
            supportingPoint2 = B + (lever2Length) * curDir;

            prevDir = curDir;

            /*
             * // Drawing supporting zigzag
             * _lineRenderer.positionCount += 3;
             * _lineRenderer.SetPosition (3 * segN, B);
             * _lineRenderer.SetPosition (3 * segN - 1,     supportingPoint2);
             * _lineRenderer.SetPosition (3 * segN - 2, supportingPoint1); Debug.LogWarning(supportingPoint1);
             */


            _lineRenderer.positionCount += _segmentsPerPair;
            for (int i = 0; i < _segmentsPerPair; i++)
            {
                float   t     = (float)i / (float)(_segmentsPerPair - 1);
                Vector3 point = CalculateBezierPoint(t, A, supportingPoint1, supportingPoint2, B);
                _lineRenderer.SetPosition((segN - 1) * _segmentsPerPair + i, point);
            }
        }
    }