User:Illviljan: Difference between revisions
Jump to navigation
Jump to search
>Illviljan No edit summary |
>Illviljan mNo edit summary |
||
Line 214: | Line 214: | ||
{| class="wikitable mw-collapsible mw-collapsed" | {| class="wikitable mw-collapsible mw-collapsed" | ||
! Leech Mechanics. Last updated: | ! Leech Mechanics. Last updated: 2016-02-03 | ||
|- | |- | ||
| | | | ||
Line 227: | Line 227: | ||
%% Input | %% Input | ||
p = 5000; % Maximum Life. | p = 5000; % Maximum Life. | ||
l = 0. | l = 0.01; % Increased Leech. | ||
m = 0; | m = 0.00; % Increased Base Leeech Rate. | ||
m_max = 0; | m_max = 0.00; % Increased Maximum Leech Rate. | ||
% Damage values from the hit: | |||
d = 1000; | |||
attacksPerSec = 4; % Attacks per Second. | |||
mobsPerAttack = 5; % Enemies hit by one attack. | |||
numberOfAttacks = 5; % Number of attacks done to enemies. | |||
% The time when the attack started: | |||
attackTime = 0:1/attacksPerSec:(numberOfAttacks - 1)/attacksPerSec; | |||
% The time when the attack hit the target(s): | |||
hitTime = kron(attackTime, ones(1,mobsPerAttack)); | |||
q = 0.02; % Base Leech Rate. | q = 0.02; % Base Leech Rate. | ||
q_max = 0.2; % Base Maximum Leech Rate. | q_max = 0.2; % Base Maximum Leech Rate. | ||
steps = 1000; % Number of steps. | steps = 1000; % Number of steps. | ||
%% Calculations | %% Calculations | ||
% Maximum recovery rate: | % Maximum recovery rate: | ||
r_max = (q_max + m_max ) * p; | r_max = (q_max + m_max) * p; | ||
% Leech duration | % Leech duration | ||
t_dur = d * l / (p *q) .* ones(1, length(hitTime)); | t_dur = floor(d * l) / (p *q) .* ones(1, length(hitTime)); | ||
% Total allowed leech instance to not exceed the maximum recovery rate | % Total allowed leech instance to not exceed the maximum recovery rate | ||
n_tot = (q_max + m_max) / (q * (1 + m)); | n_tot = (q_max + m_max) / (q * (1 + m)); | ||
% Maximum analysis time: | % Maximum analysis time: | ||
Line 267: | Line 267: | ||
% Boolean conditions to check if there have been an enemy hit and if | % Boolean conditions to check if there have been an enemy hit and if | ||
% the leeched ife is lower than the total amount of life leeched. | % the leeched ife is lower than the total amount of life leeched. | ||
boolHitStart = tRep >= AttackTimeRep; | boolHitStart = tRep >= AttackTimeRep; | ||
boolLeechEnd = tRep < AttackTimeRep + t_durRep; | boolLeechEnd = tRep < AttackTimeRep + t_durRep; | ||
BoolLeechEndVP = tRep <= AttackTimeRep + (maxTime-0)/steps; | |||
% Both of the above conditions must be true for leech to occur: | % Both of the above conditions must be true for leech to occur: | ||
boolLeech = (boolHitStart .* boolLeechEnd); | boolLeech = (boolHitStart .* boolLeechEnd); | ||
boolLeechVP = (boolHitStart .* BoolLeechEndVP); | |||
% Base Recovery Rate for each leech instance: | % Base Recovery Rate for each leech instance: | ||
r = ( | r = p * q * (1 + m) .* boolLeech; | ||
% Each active leech instance: | % Each active leech instance: | ||
Line 280: | Line 282: | ||
% Base Recovery Rate summarized for all the leech instances: | % Base Recovery Rate summarized for all the leech instances: | ||
r_sum = sum(r); | r_sum = sum(r,1); | ||
% Check that r_sum is not greater than r_max: | % Check that r_sum is not greater than r_max: | ||
Line 290: | Line 292: | ||
HP_i = zeros(length(hitTime),length(t)); | HP_i = zeros(length(hitTime),length(t)); | ||
HP_tot = zeros(1,length(t)); | HP_tot = zeros(1,length(t)); | ||
HP_totVP = zeros(1,length(t)); | |||
for i = 1:length(t)-1; | for i = 1:length(t)-1; | ||
Line 298: | Line 301: | ||
% Total HP restored from all the leech instances: | % Total HP restored from all the leech instances: | ||
HP_tot(:,i+1) = r_sum(:,i) * dt + HP_tot(:,i); | HP_tot(:,i+1) = r_sum(:,i) * dt + HP_tot(:,i); | ||
% Vaal Pact restores life instanteously: | |||
HP_totVP(:,i+1) = d * l .* sum(boolLeechVP(:,i),1) + HP_totVP(:,i); | |||
end | end | ||
Line 304: | Line 310: | ||
leechInstance(leechInstance == 0) = NaN; % Remove zeros from plot. | leechInstance(leechInstance == 0) = NaN; % Remove zeros from plot. | ||
fig(1) = subplot(3,1,1); | fig(1) = subplot(3,1,1); | ||
plot(t, leechInstance(:,:)); | colororder = get(gca,'colororder'); | ||
plot(t, leechInstance, 'Color', colororder(1,:)); | |||
% set(gca, 'YTick', 0:length(hitTime)); % Show integers only. | |||
ylim([0 length(hitTime)+0.5]); | ylim([0 length(hitTime)+0.5]); | ||
xlim([0 maxTime]); | xlim([0 maxTime]); | ||
Line 315: | Line 323: | ||
[rowStart, colStart] = find(~isnan(leechInstance(i,:)), 1, 'first'); | [rowStart, colStart] = find(~isnan(leechInstance(i,:)), 1, 'first'); | ||
[rowEnd, colEnd] = find(~isnan(leechInstance(i,:)), 1, 'last'); | [rowEnd, colEnd] = find(~isnan(leechInstance(i,:)), 1, 'last'); | ||
plot(t(colStart), leechInstance(i, colStart), '.', ... | plot(t(colStart), leechInstance(i, colStart), 'b.', ... | ||
t(colEnd), leechInstance(i, colEnd), ' | t(colEnd), leechInstance(i, colEnd),'bx', ... | ||
t(colStart), leechInstance(i, colStart),'ro'); | |||
% Vaal Pact Start and End: | |||
plot(t(colStart), leechInstance(i, colStart),'ro'); | |||
end | end | ||
fig(2) = subplot(3,1,2); | fig(2) = subplot(3,1,2); | ||
[ | [ax, h1, h2] = plotyy(t, r_sum, t, r_sum/p); | ||
delete(h2); | delete(h2); | ||
NumberOfTicks = 4; | NumberOfTicks = 4; | ||
set( | set(ax(1), 'ycolor', 'black', ... % Change right axis color to black | ||
'YTick', 0:r_max/NumberOfTicks:r_max); | 'YTick', 0:r_max/NumberOfTicks:r_max); | ||
set( | set(ax(2), 'ycolor', 'black', ... % Change left axis color to black | ||
'YTick', 0:q_max/NumberOfTicks:q_max); % | 'YTick', 0:(q_max+m_max)/NumberOfTicks:(q_max+m_max)); % | ||
ylim( | ylim(ax(1), [0 r_max]); | ||
ylim( | ylim(ax(2), [0 q_max+m_max]); | ||
xlim([0 maxTime]); | xlim([0 maxTime]); | ||
xlabel('Time, t, [s]'); | xlabel('Time, t, [s]'); | ||
ylabel( | ylabel(ax(1), 'Recovery rate [HP/s]'); | ||
ylabel( | ylabel(ax(2), 'Base Rate [HP/(max hp * s)]'); | ||
title(' | title('Leech Rate'); | ||
fig(3) = subplot(3,1,3); | fig(3) = subplot(3,1,3); | ||
plot(t, HP_tot); | plot(t, HP_tot, 'b', t, HP_totVP, 'r-.'); | ||
ylim([0 inf]); | ylim([0 inf]); | ||
xlim([0 maxTime]); | xlim([0 maxTime]); | ||
Line 342: | Line 353: | ||
ylabel('HP restored, [HP]'); | ylabel('HP restored, [HP]'); | ||
title('HP restored from leech'); | title('HP restored from leech'); | ||
legend('Recovery rate','Instantenous leech', 'Location','SouthEast') | |||
linkaxes(fig,'x') | linkaxes(fig,'x') | ||
Revision as of 12:59, 3 February 2016
Collapsible Template |
---|
Text here |
Matlab scripts | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|