Skip to content

Commit

Permalink
All damage method added
Browse files Browse the repository at this point in the history
  • Loading branch information
John Taoi committed Apr 26, 2024
1 parent e9c3d92 commit 4d37312
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 89 deletions.
27 changes: 22 additions & 5 deletions app/src/main/java/com/example/proj2/Classes/Ability.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,25 +274,42 @@ public double returnDamage(Champion champ){
return 0;
}
public double returnADDamage(Champion champ){
Log.d("Working on Abi", Name);
Log.d("Working on Abi", String.valueOf(rank));
//check if this ab does dmg
if(isDamage == true&&damageType==0){
return damage.get(rank-1)*instances +(ratioAD == null ? 0.0 : ratioAD.get(rank-1)*champ.getBaseDamage()) + (ratioBAD.get(rank-1) == null ? 0.0 : ratioBAD.get(rank-1)) + (ratioAP.get(rank-1) == null ? 0.0 : ratioAP.get(rank-1)* champ.getAp())
return damage.get(rank-1)*instances
+ (ratioAD == null ? 0.0 : ratioAD.get(rank-1)*champ.getBaseDamage())
+ (ratioBAD == null ? 0.0 : ratioBAD.get(rank-1))
+ (ratioAP== null ? 0.0 : ratioAP.get(rank-1)* champ.getAp())
+ returnDOT(champ)
+ returnSummonDamage(champ); }
+ returnSummonDamage(champ);
}
return 0;
}
public double returnAPDamage(Champion champ){
Log.d("Working on Abi", Name);
Log.d("Working on Abi", String.valueOf(rank));
//check if this ab does dmg
if(isDamage == true&&damageType==1){
return damage.get(rank-1)*instances +(ratioAD.get(rank-1) == null ? 0.0 : ratioAD.get(rank-1)*champ.getBaseDamage()) + (ratioBAD.get(rank-1) == null ? 0.0 : ratioBAD.get(rank-1)) + (ratioAP.get(rank-1) == null ? 0.0 : ratioAP.get(rank-1)* champ.getAp())
return damage.get(rank-1)*instances
+ (ratioAD == null ? 0.0 : ratioAD.get(rank-1)*champ.getBaseDamage())
+ (ratioBAD == null ? 0.0 : ratioBAD.get(rank-1))
+ (ratioAP== null ? 0.0 : ratioAP.get(rank-1)* champ.getAp())
+ returnDOT(champ)
+ returnSummonDamage(champ); }
+ returnSummonDamage(champ);
}
return 0;
}
public double returnTrueDamage(Champion champ){
Log.d("Working on Abi", Name);
Log.d("Working on Abi", String.valueOf(rank));
//check if this ab does dmg
if(isDamage == true&&damageType==2){
return damage.get(rank-1)*instances +(ratioAD.get(rank-1) == null ? 0.0 : ratioAD.get(rank-1)*champ.getBaseDamage()) + (ratioBAD.get(rank-1) == null ? 0.0 : ratioBAD.get(rank-1)) + (ratioAP.get(rank-1) == null ? 0.0 : ratioAP.get(rank-1)* champ.getAp())
return damage.get(rank-1)*instances
+ (ratioAD == null ? 0.0 : ratioAD.get(rank-1)*champ.getBaseDamage())
+ (ratioBAD == null ? 0.0 : ratioBAD.get(rank-1))
+ (ratioAP== null ? 0.0 : ratioAP.get(rank-1)* champ.getAp())
+ returnDOT(champ)
+ returnSummonDamage(champ);
}
Expand Down
51 changes: 42 additions & 9 deletions app/src/main/java/com/example/proj2/Classes/Champion.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public void setAbilities(ArrayList<Ability> abilities) {
double baseDamage;
double damagePerLevel;
double ap;
double critChance;
double critDamage;
double lifeSteal;
double omniVamp;
double armorPen;
double magicPen;
double lethality;
double magicFlatPen;
double critChance = 0;
double critDamage = 0.75;
double lifeSteal = 0;
double omniVamp = 0;
double armorPen = 0;
double magicPen = 0;
double lethality = 0;
double magicFlatPen = 0;
double baseHP;
double hpPerLevel;
double baseArmor;
Expand Down Expand Up @@ -57,6 +57,15 @@ public Champion() {
this.attackSpeed = 0;
this.attackSpeedRatio = 0;
this.attackSpeedPerLevel = 0;
this.critChance = 0;
this.critDamage = 0.75;
this.lifeSteal = 0;
this.omniVamp = 0;
this.armorPen = 0;
this.magicFlatPen = 0;
this.magicPen = 0;
this.lethality = 0;

}
//Constructor
public Champion(String name,
Expand Down Expand Up @@ -227,9 +236,33 @@ public double returnCombineDamage(){
double wDamage = abilities.get(1).returnDamage(this);
double eDamage = abilities.get(2).returnDamage(this);
double rDamage = abilities.get(3).returnDamage(this);
Log.d("Combine Dmg" ,String.valueOf(getBaseDamage() + qDamage + wDamage + eDamage+ rDamage));
//Log.d("Combine Dmg" ,String.valueOf(getBaseDamage() + qDamage + wDamage + eDamage+ rDamage));
return getBaseDamage()+ getDamagePerLevel()* getLevel() + qDamage + wDamage + eDamage+ rDamage;
}
public double returnADDamage(){
double qDamage = abilities.get(0).returnADDamage(this);
double wDamage = abilities.get(1).returnADDamage(this);
double eDamage = abilities.get(2).returnADDamage(this);
double rDamage = abilities.get(3).returnADDamage(this);
//Log.d("AD Dmg" ,String.valueOf(getBaseDamage() + qDamage + wDamage + eDamage+ rDamage));
return getBaseDamage()+ getDamagePerLevel()* getLevel() + qDamage + wDamage + eDamage+ rDamage;
}
public double returnAPDamage(){
double qDamage = abilities.get(0).returnAPDamage(this);
double wDamage = abilities.get(1).returnAPDamage(this);
double eDamage = abilities.get(2).returnAPDamage(this);
double rDamage = abilities.get(3).returnAPDamage(this);
//Log.d("AP Dmg" ,String.valueOf(getBaseDamage() + qDamage + wDamage + eDamage+ rDamage));
return qDamage + wDamage + eDamage+ rDamage;
}
public double returnTrueDamage(){
double qDamage = abilities.get(0).returnAPDamage(this);
double wDamage = abilities.get(1).returnAPDamage(this);
double eDamage = abilities.get(2).returnAPDamage(this);
double rDamage = abilities.get(3).returnAPDamage(this);
//Log.d("TRUE Dmg" ,String.valueOf(getBaseDamage() + qDamage + wDamage + eDamage+ rDamage));
return qDamage + wDamage + eDamage+ rDamage;
}



Expand Down
66 changes: 2 additions & 64 deletions app/src/main/java/com/example/proj2/Classes/ChampionViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,70 +32,6 @@ public class ChampionViewModel extends ViewModel {
enum qwer{Qability,Wability,Eability,Rability};
public LiveData<Champion> getChampion() {
return championData;
}
public void fetchChampionAbility(String championName, Champion champ){
FirebaseFirestore db = FirebaseFirestore.getInstance();

for(int i =0; i<4;i++){
String abilitySlot = "";
switch (i){
case 0:
abilitySlot = "Qability";
break;
case 1:
abilitySlot = "Wability";
break;
case 2:
abilitySlot = "Eability";
break;
case 3:
abilitySlot = "Rability";
break;
default:
break;
}

//Getting data from database
DocumentReference docRef = db.collection("championAbility")
.document(championName).collection(abilitySlot).document("data");

// Asynchronously retrieve the document
docRef.get().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
// Log the document snapshot data
Log.d("Print", "DocumentSnapshot data: " + document.getData());

// Convert the document snapshot to Ability object
Ability ability = document.toObject(Ability.class);

if (ability != null) {
// Since we only fetched Qability, let's add it to a new list of abilities
ArrayList<Ability> abilities = new ArrayList<>();
abilities.add(ability);

// Set the abilities in the Champion object
champ.setAbilities(abilities);

// For debugging, log the name of the ability and the damage array
Log.d("Ability", "Name: " + ability.getName());
Log.d("Ability", "Damage: " + ability.getDamage().toString());
} else {
Log.d("Firestore Conversion", "Failed to convert document to Ability object.");
}
} else {
Log.d("Firestore Fetch", "No such document");
}
} else {
Log.d("Firestore Fetch", "get failed with ", task.getException());
}
});
}

}
public void fetchChampionAbilities(String championName, Champion champ) {

}
public void fetchChampionData(Context context, String championName) {
if (queue == null) {
Expand Down Expand Up @@ -130,6 +66,7 @@ public void fetchChampionData(Context context, String championName) {
final int[] abilitiesFetchedCount = {0};

for (qwer abilitySlot : qwer.values()) {
Log.d("Now Fetching",abilitySlot.toString());
String collectionPath = abilitySlot.toString();
DocumentReference docRef = db.collection("championAbility")
.document(championName.replaceAll("\\s", "").toLowerCase()).collection(collectionPath).document("data");
Expand All @@ -138,6 +75,7 @@ public void fetchChampionData(Context context, String championName) {
abilitiesFetchedCount[0]++;
if (task.isSuccessful() && task.getResult().exists()) {
Ability ability = task.getResult().toObject(Ability.class);

if (ability != null) {
Log.d("Ability added", "Name: " + ability.getName());
abilities.add(ability);
Expand Down
59 changes: 59 additions & 0 deletions app/src/main/java/com/example/proj2/Classes/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.example.proj2.Classes;

public class Item {
String Name;
double AD = 0;
double AP = 0;
double HP = 0;
double MR = 0;
double ARMOR = 0;
double Haste = 0;

public String getName() {
return Name;
}

public void setName(String name) {
Name = name;
}

public double getAD() {
return AD;
}

public void setAD(double AD) {
this.AD = AD;
}

public double getAP() {
return AP;
}

public void setAP(double AP) {
this.AP = AP;
}

public double getHP() {
return HP;
}

public void setHP(double HP) {
this.HP = HP;
}

public double getMR() {
return MR;
}

public void setMR(double MR) {
this.MR = MR;
}

public double getARMOR() {
return ARMOR;
}

public void setARMOR(double ARMOR) {
this.ARMOR = ARMOR;
}
}
16 changes: 15 additions & 1 deletion app/src/main/java/com/example/proj2/SecondFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

import org.json.JSONObject;

import java.math.BigDecimal;

public class SecondFragment extends Fragment {

private FragmentSecondBinding binding;
Expand Down Expand Up @@ -110,7 +112,19 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
ViewModel viewModel = new ViewModelProvider(this).get(ChampionViewModel.class);
((ChampionViewModel) viewModel).getChampion().observe(getViewLifecycleOwner(), champion -> {
if (champion != null) {
champion.returnCombineDamage();
String formattedValue = String.format("%.1f", champion.returnCombineDamage());
TextView combineDMG = binding.combineDamageDisplay;
combineDMG.setText(formattedValue);
//ad
TextView physicalDMG = binding.physicalDamageDisplay;
formattedValue = String.format("%.1f", champion.returnADDamage());
Log.d("ad",String.valueOf(champion.returnADDamage()));
physicalDMG.setText(formattedValue);
//ap
TextView magicalDmG = binding.magicalDamageDisplay;
formattedValue = String.format("%.1f", champion.returnAPDamage());
Log.d("ap",String.valueOf(champion.returnAPDamage()));
magicalDmG.setText(formattedValue);
}else{
Log.d("Failed","failed");
}
Expand Down
20 changes: 10 additions & 10 deletions app/src/main/res/layout/fragment_second.xml
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Dance Of Arrow"
android:text="Loading"
android:layout_below="@+id/currentItemTitletext"
android:textColor="@color/black"
android:textSize="16sp" />
Expand All @@ -370,7 +370,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Dance Of Arrow"
android:text="Loading"
android:layout_below="@+id/abilityQ"
android:textColor="@color/black"
android:textSize="16sp" />
Expand All @@ -380,7 +380,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Dance Of Arrow"
android:text="Loading"
android:layout_below="@+id/abilityW"
android:textColor="@color/black"
android:textSize="16sp" />
Expand All @@ -390,7 +390,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Dance Of Arrow"
android:text="Loading"
android:layout_below="@+id/abilityE"
android:textColor="@color/black"
android:textSize="16sp" />
Expand Down Expand Up @@ -466,38 +466,38 @@
android:textSize="18sp" />

<TextView
android:id="@+id/rawValue2"
android:id="@+id/combineDamageDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/maxDamageTitle"
android:layout_alignEnd="@+id/rawText2"
android:layout_marginTop="0dp"
android:layout_marginEnd="-93dp"
android:text="1200 "
android:text="Loading"
android:textColor="@color/black"
android:textSize="18sp" />

<TextView
android:id="@+id/pysicalValue2"
android:id="@+id/physicalDamageDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/maxDamageTitle"
android:layout_alignEnd="@+id/rawText2"
android:layout_marginTop="23dp"
android:layout_marginEnd="-92dp"
android:text="800 "
android:text="Loading"
android:textColor="@color/black"
android:textSize="18sp" />

<TextView
android:id="@+id/magicalValue2"
android:id="@+id/magicalDamageDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/maxDamageTitle"
android:layout_alignEnd="@+id/rawText2"
android:layout_marginTop="47dp"
android:layout_marginEnd="-91dp"
android:text="300 "
android:text="Loading"
android:textColor="@color/black"
android:textSize="18sp" />

Expand Down

0 comments on commit 4d37312

Please sign in to comment.