public void Execute(TriggerEvent triggerEvent)
            {
                Entity entityA = triggerEvent.EntityA;
                Entity entityB = triggerEvent.EntityB;

                if (!potentialGroup.HasComponent(entityA) ||
                    !potentialGroup.HasComponent(entityB))
                {
                    return;
                }

                Translation translationA = translationGroup[entityA];
                Translation translationB = translationGroup[entityB];

                HighestPotentialAgent highestPotentialAgentA = highestPotentialtGroup[entityA];
                HighestPotentialAgent highestPotentialAgentB = highestPotentialtGroup[entityB];

                PotentialValue potentialA = potentialGroup[entityA];
                PotentialValue potentialB = potentialGroup[entityB];

                if (potentialB.Value > highestPotentialAgentA.Potential)
                {
                    highestPotentialAgentA.Potential = potentialB.Value;
                    highestPotentialAgentA.Direction = math.normalize(translationB.Value - translationA.Value);
                }

                if (potentialA.Value > highestPotentialAgentB.Potential)
                {
                    highestPotentialAgentB.Potential = potentialA.Value;
                    highestPotentialAgentB.Direction = math.normalize(translationA.Value - translationB.Value);
                }

                highestPotentialtGroup[entityA] = highestPotentialAgentA;
                highestPotentialtGroup[entityB] = highestPotentialAgentB;
            }
Exemplo n.º 2
0
            public void Execute(TriggerEvent triggerEvent)
            {
                Entity entityA = triggerEvent.EntityA;
                Entity entityB = triggerEvent.EntityB;

                if (!potentialGroup.HasComponent(entityA) ||
                    !potentialGroup.HasComponent(entityB))
                {
                    return;
                }

                PotentialValue potentialA = potentialGroup[entityA];
                PotentialValue potentialB = potentialGroup[entityB];

                if (potentialA.Value < 0.00001f)
                {
                    potentialA.Value = 0;
                }

                if (potentialB.Value < 0.00001f)
                {
                    potentialB.Value = 0;
                }

                if (potentialA.Value > potentialB.Value)
                {
                    float difference = (potentialA.Value - potentialB.Value) * transferRate;
                    potentialA.Value -= difference;
                    potentialB.Value += difference;
                }
                else
                {
                    float difference = (potentialB.Value - potentialA.Value) * transferRate;
                    potentialB.Value -= difference;
                    potentialA.Value += difference;
                }

                potentialGroup[entityA] = potentialA;
                potentialGroup[entityB] = potentialB;
            }