How do we know which ions each element forms? And how do assign charges in complex ions?
Use the periodic table.
Periodic table is arranged such that most common oxidation state of the elements are represented as column numbers. All elements with same valence electrons in the outer shell are arranged column-wise. Remembering the position of the element or even the group of the element is sufficient. The left half of the periodic table has increasing positive valencies while the right half has decreasing negative valencies.
You have listed 1 element,
To continue, we consider elemental chlorine,
Each chlorine atom now has 7 electrons, and is therefore electronically neutral. It has a zero oxidation state. If it were a chloride ion,
As for compound ions, let's go to chlorates, salts of chloric acid,
We would have got the same result and considered the parent chloric acid,